-3

I have to face session problem in my new server.

Session not working properly for this link

I have refreshed page not show session and then again refresh page with Ctrl+f5 then session show.

So please tell me this is a server issue or coding issue ??

have a coding issue than solution me any one.

visit link to see phpinfo() : http://brahmanparivar.com/phpinfo.php

index.php and display.php

<?php session_start();  ?>
    <html>
       <head>
          <title>PHP session</title>
       </head>
       <body>       
           <? if(isset( $_SESSION['name'] ) ){ 
                echo $_SESSION['name'];
           } else{
           echo "not have a Session";
       } ?>
       <br><br>
    <a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
       </body>
    </html>

logout.php

<?php session_start(); ?>
<html>
<body>
<?php
   if(isset( $_SESSION['name'] ) ){
      session_destroy();
   }else{
       echo "not have a Session";
   }
?>
<br><br>
<a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
</body></html>

set.php

<?php session_start(); 
$_SESSION['name']="Session Set";  ?>
<html>
   <head>
      <title>PHP session</title>
   </head>
   <body>       
       <? if(isset( $_SESSION['name'] ) ){ 
       echo "Set a Session :: Session Set";
   } ?>
   <br><br>
       <a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
   </body>
</html>
Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

0

in your logout.php page, you are missing a php open tag <?php.

Change this:

 <? if (isset($_SESSION['name'])) {...

to this:

<?php if (isset($_SESSION['name'])) {...
CodeGodie
  • 12,116
  • 6
  • 37
  • 66
0

I dont think short tag fixes his problem. When i ran your code it works perfectly. Probably it's configuration issue.

Please read: How to get my session to write to apache

see if that fixes your problem for further trouble shooting

I would like to see the phpinfo();

also attach

<?php 
session_start(); 
echo session_id(); 
?>

to every page I dont think your PHPSESSIONID is not being set. properly

Community
  • 1
  • 1
Tom
  • 81
  • 5
  • What is your permission on /tmp/ and does your user agent has access to that folder? I cant get the session to set at all now. – Tom Dec 24 '15 at 18:43
  • Actually that might not be it it works fine with curl – Tom Dec 24 '15 at 18:56
  • `curl -c a http://brahmanparivar.com/session/set.php` `curl -b a http://brahmanparivar.com/session/index.php` `curl -b a http://brahmanparivar.com/session/display.php` – Tom Dec 24 '15 at 18:56