Jump to content

session vars


pacome

Recommended Posts

I'm trying to pass some variables through a session with PHP 4.329 but I can't manage to get them through the pages...

My host's has this info

Session Support  enabled 
Registered save handlers  files user 

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /var/lib/php/session /var/lib/php/session
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off

and my script is page 1:

<?php
session_start();
session_name('ses');
if ($_POST[nicksess])
{
$nicksess=$_POST['nicksess'];
//$nicksess=$_POST[nicksess];
//session_register("nicksess");
echo "<html><body><a href='page2.php'>go to page 2</a><br>".$_POST['nicksess']." <br>y ".$nicksess."</body></html>";
}
else {

?>
<html><head></head>
<body>
<form action='page1.php' method='POST'>
<input type='text' name='nicksess'>Name<br>
<input type='password' name='pass'><br>
<input type='submit' name='submit' value='submit'></form>
</body></html>
<?php
}
?>


and page 2 is:

<?php
session_start();
session_name('ses');
echo "<html><body>Mi nick es:".$_SESSION["nicksess"]." </body></html>";

?>

When I put my name I print correctly $_SESSION["nicksess"] and $nicksess, but when I click to page 2 the nick doesn't print! :(

any ideas?

thanks!
Link to comment
https://forums.phpfreaks.com/topic/31766-session-vars/
Share on other sites

You don't store the variable in the $_SESSION array in your first script, so you can't get it in your second script.

Change:
[code]<?php
if ($_POST[nicksess])
{
$nicksess=$_POST['nicksess'];
?>[/code]

to
[code]<?php
if ($_POST[nicksess])
{
$nicksess=$_POST['nicksess'];
$_SESSION['nicksess'] = $_POST['nicksess'];
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/31766-session-vars/#findComment-147308
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.