Jump to content
  • Advertisement
Sign in to follow this  
sooner123

[web] Sessions not working correctly

This topic is 2587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Simple sessions not working:

1.php


<?php
session_start();
$_SESSION[test] = 3;
echo "<a href='2.php'>2</a>";
?>


2.php


<?php
session_start();
echo $_SESSION[test];
?>





It will not display the 3 on the second page. But if they keep trying and trying and trying and trying like 50 times, eventually it works.

Then it works forever.

So what gives? The browser have to be "broken in" to sessions or something?

And why don't my sessions work but logins on other websites work fine the first time, despite sessions being how they do it as well.

Share this post


Link to post
Share on other sites
Advertisement

Simple sessions not working:

1.php


<?php
session_start();
$_SESSION[test] = 3;
echo "<a href='2.php'>2</a>";
?>


2.php


<?php
session_start();
echo $_SESSION[test];
?>





It will not display the 3 on the second page. But if they keep trying and trying and trying and trying like 50 times, eventually it works.

Then it works forever.

So what gives? The browser have to be "broken in" to sessions or something?

And why don't my sessions work but logins on other websites work fine the first time, despite sessions being how they do it as well.


try putting quotes around test


<?php
session_start();
$_SESSION['test'] = 3;
echo "<a href='2.php'>2</a>";
?>



<?php
session_start();
echo $_SESSION['test'];
?>

Share this post


Link to post
Share on other sites
You should probably change

[php]$_SESSION[test][/php]
to

[php]$_SESSION['test'][/php]


If that still isn't working, here are a few ideas you might want to try:

  • Add [font="Courier New"]error_reporting(E_ALL); [/font]straight after the [font="Courier New"]<?php [/font]line.
    • Check that cookies are enabled in your browser. You could also test it in a different browser (especially if you're using IE).
      • Make sure that the code you posted is the very first thing in each file (no whitespace or html before it).
        • Run this code:
          [php]
          <?php
          phpinfo(INFO_MODULES);
          ?>
          [/php]
          Skip down to the section titled 'session', and check that session support is enabled. If you have been messing around with the settings, you might want to compare them to the defaults found here.


          I hope I've been able to help smile.gif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!