Jump to content

[SOLVED] $_SESSION not sent across multiple pages....


bobbyM

Recommended Posts

Hi,

 

I am using the following:

Apache version 1.3.37 (Unix)

PHP version 4.4.4

MySQL version 4.1.22-standard

 

I have a page which sets a few $_SESSION variables as such:

$_SESSION['username'] = Bobby;

$_SESSION['authentic'] = 1;

 

I didn't use session_start(); at the beginning of this page because from what I read elsewhere there is no need to when using $_SESSION[](only when using session_register()). Now, when I click a link and go to a new page (same domain and same window) none of the $_SESSION variables are read. I just get empty when I echo $_SESSION['username'].

 

Anybody have any ideas? Thanks :)

Link to comment
Share on other sites

Hrm, i added it to the top of my index.php page and I get the same result. I'll try showing you what I have done.

 

Index.php

 

<?php
session_start();	
  	include('../constant.php');
  	include('../incl.php');
?> 
<html><head></head>
<?php
$password = $_POST['password'];
$username = $_POST['username'];

$enc_password = md5(sha1($password));

$query = "SELECT users_id, username, admin
		  FROM users
		  WHERE username = '". $username ."' AND password = '". $enc_password ."'";
$result = mysql_query($query);

$row = mysql_num_rows($result) or die(mysql_error());

if($row)
{
	while($rows = mysql_fetch_row($result))
	{	    
		$_SESSION['id'] = $rows[0];
		$_SESSION['username'] = $rows[1];
		$_SESSION['authentic'] = 1;
		$_SESSION['admin'] = $rows[2];
              }
             }
             include(menu.php); //bad formto include like this? No clue.....

 

 

menu.php simplified

<html><head></head>
<body>
<?php
echo '<a href="cart.php">Cart</a>';
?>
</body></html>

 

finally, cart.php where the $_SESSION variables aren't showing

<html>
<head>
<body>
<?php 	 
echo "hi";
echo $_SESSION['admin'].'is admin';
echo $_SESSION['username'].'is user'; ?>
</body></head></html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.