Jump to content

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

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.