Jump to content

$_SESSION


lapfama

Recommended Posts

Hello,

 

I'm having a real tough time with session variables.

The values don't pass from one page to the next one.

Even with a very simple code like this one:

 

Page#1

<?php   
  session_start();
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
        $_SESSION['FName']="Jay";
        $_SESSION['LName']="Pay";
        echo "<a href='session2.php'>Try now</a>";
?>

</body>
</html>


 

Page#2

<?php  
   session_start();
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
  echo "My name is ".$_SESSION['FName']. " ". $_SESSION['LName'] ;
?>

</body>
</html>

Thanks in advance for your comments.

 

Laura

Link to comment
https://forums.phpfreaks.com/topic/111129-_session/
Share on other sites

Add the following two lines after your first opening <?php tag on both pages -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

@mark110384, session_register was depreciated long ago in 2002, it only works when register_globals are on, and it, along with register_globals, have been completely removed in php6.

Link to comment
https://forums.phpfreaks.com/topic/111129-_session/#findComment-570326
Share on other sites

It might not like that because of the outputting before sending headers....  If output buffering isn't on, try the following.  (Although, if this is the case, PFMaBiSmAd's code should've made it show....  Oh wait!  Try changing "ini_set ("display_errors", "1");"  to "ini_set ("display_errors", "on");")

 

Anyway, try the following:

 

<?php   
  session_start();
$_SESSION['FName']="Jay";
        $_SESSION['LName']="Pay";
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<a href="session2.php">Try now</a>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/111129-_session/#findComment-570426
Share on other sites

Thanks to everyone that try to contribute.

And special thanks to PFMaBiSmAd.

His comment "either the php code is not being parsed/executed" turned on the light.

I contacted my web host, and the problem was that the path for the PHP Scripting needed to be upddated.

Thanks again,

 

Laura

Link to comment
https://forums.phpfreaks.com/topic/111129-_session/#findComment-570450
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.