...

View Full Version : Session



weronpc
04-20-2003, 02:34 AM
Hello, I am having problem passing a session veriable to another page.

Singin.php contains :
session_start();
$_SESSION['user'] = $user;
echo "<a href=check_session.php>next page</a>";

In the check_session.php page contains :
session_start();
$user=$_SESSION['user']; //This is line 3
echo "the user name is $user";

When I clicked on the link to check_session.php, it doesn't display the user name, but with the notice message :
Notice: Undefined index: user in C:\user\share\public\web\check_sesion.php on line 3

Also, when should I use the session_register?

Thank you all

Mike

Nightfire
04-20-2003, 04:06 AM
Which version of PHP are you using?

Try adding print_r($_SESSION); into the page, that'll tell you if there's anything in the session. If you don't get anything, I'm assuming you're on an older version of php and you might want to use $HTTP_SESSION_VARS['user'] instead of $_SESSION

weronpc
04-20-2003, 05:37 AM
Thanks for your reply, I had tried everything you told me to.

but none of them seem to work.

when I put print_r($_SESSION); it outputs
Array ( )
//empty array....

So it mean, I am not passing the Session value properly.

Notice: Undefined index: user in C:\user\share\public\web\check_session.php on line 3

I am using the newest version php.

Thank you,

Mike

Spookster
04-20-2003, 06:26 AM
In your signin page echo out the session variable after you set it just to make sure it is even getting put into the session:

$_SESSION['user'] = $user;
echo "<a href=check_session.php>next page</a>";
echo "User = " . $_SESSION['user'];

weronpc
04-20-2003, 07:51 AM
Yup, when I echo the variable in the singin.php page, it works fine, just not in the check_session.php

don't know why, I can't pass session variable to another page..

can someone make a small testing session script for me (working script)? I just want to make sure my server works with session.

Do I have to do any setting with the php.ini file?

Thank you all,

Mike

Spookster
04-20-2003, 08:04 AM
The code you have posted should work just fine. If you can access the session variable in the one page then everything is working just fine. There must be something else wrong. Paste the exact contents of the check_session.php page here in this thread.

missing-score
04-20-2003, 11:30 AM
Try printing $_SESSION['user'] in the check session page, just to make sure its not somewhere else, I would try that.

Id does look like it should work fine though, so like spooks said, post the code.

weronpc
04-20-2003, 03:57 PM
Login.php
case 1:
session_start();
$ip = $_SERVER['REMOTE_ADDR'];
$_SESSION['user'] = "mikemike";
$_SESSION['ip'] = $ip;
echo "<a href=\"check_session.php\">check</a>";

echo "user : $_SESSION[user] and ip : $_SESSION[ip]"; //works fine here, display both perfect...
break;

check_session.php
<?php
session_start();
$users=$HTTP_SESSION_VARS['user'];
echo "hello user : $users"; //doesn't display $users

$ips=$_SESSION['ip'];
echo "<br />the ip is $ips"; //doesn't display $ips

print_r($_SESSION); //it prints out Array()
?>

Thank you all for your help,

Mike

missing-score
04-20-2003, 04:16 PM
Ummm. Looks fine to me.

2 things:

Why are you using break? I might have missed something, but there seems to be no reason for it.

Why are you using $_SESSION AND $HTTP_SESSION_VARS?


There seems to be no reason why it isn't working. :confused:

missing-score
04-20-2003, 04:19 PM
Sorry, missed the case1: bit.

Try printing the session var After break. Shouldnt make a difference, but its worth a try. :confused:

weronpc
04-20-2003, 05:10 PM
Nope, it didn't work...

Do you think I have to do some changes in the php.ini file?

missing-score
04-20-2003, 05:15 PM
Possibly, but I wouldn't have thought so. If the session is recognising on one page, it should on the other too.

Spookster
04-20-2003, 05:29 PM
Ok when you are debugging a problem such as this it is best to try something basic and simple. You can do this in those pages or do this in two other pages.

In one page just create a session and set a variable:




<html>
<body>

<?php

session_start();
$_SESSION["test"] = "testing";

?>

<a href="otherpage.php">Other page</a>

</body>
</html>



in the other page:




<html>
<body>

<?php

session_start();
echo "The test variable = " . $_SESSION["test"];
session_destroy();

?>

</body>
</html>

weronpc
04-20-2003, 07:04 PM
I tried your testing pages. I took out the html tags because can't start session after the tags.

anyway, same error message:

Notice: Undefined index: test in C:\user\share\public\web\developer\account\test2.php on line 4
The test variable =

Spookster
04-22-2003, 07:09 AM
Ok paste these into new pages and test them on your server. I have them on mine right now and everything works fine.

contents of session1.php




<?php
session_start();
?>

<html>
<head>
<title>Session Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php
$_SESSION["test"] = "testing";
?>

<a href="session2.php">Session2.php</a>
</body>
</html>




contents of session2.php




<?php
session_start();
?>

<html>
<head>
<title>Session Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php
echo "The test variable = " . $_SESSION["test"];
?>

</body>
</html>



If that doesn't work then something else is obviously wrong. You can see them in action on my server to see what should happen:

http://www.designqueue.com/session1.php
http://www.designqueue.com/session2.php

weronpc
04-22-2003, 02:45 PM
I copied your code and here is the errors

Warning: session_start() [function.session-start]: open(/tmp\sess_870c51431bca196dc8722e7307254254, O_RDWR) failed: No such file or directory (2) in C:\Program Files\BadBlue\PE\web\session1.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\BadBlue\PE\web\session1.php:2) in C:\Program Files\BadBlue\PE\web\session1.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\BadBlue\PE\web\session1.php:2) in C:\Program Files\BadBlue\PE\web\session1.php on line 2
Session2.php
Warning: Unknown(): open(/tmp\sess_870c51431bca196dc8722e7307254254, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

Do you know what is all these warning message mean???

Mike

missing-score
04-22-2003, 02:50 PM
Right, that means you have no /tmp directory to store your session information.

I am having the same problem with phpdev5, so if anyone can help us... :p

weronpc
04-22-2003, 03:10 PM
Thank you all so so so much...

my problem was

I have 2 php.ini files, one is called php.ini-recommended and the other one is called php.ini-dist.

I just change php.ini-recommended to php.ini and change session.save_path = C:\php Win32\tmp (full path to tmp)

it works.

One more question, why do I had php.ini-recommended and php.ini-dist? what is the different of them 2?

Thanx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum