Note that there are some explanatory texts on larger screens.

plurals
  1. POsession not working properly in php
    text
    copied!<p>I have a problem with session. I have 3 php pages login, home and edit. When i login session is created successfully and goes to home. In home I have a link which goes to edit. But when i go to edit the session is unset. I tried to echo session value in both pages. It successfully shows session value in home but not in edit. What might be the problem? Please help.</p> <p>login.php</p> <pre><code> if($countStudent == 1){ $_SESSION['stuName']= $username; header("location:studenthome.php"); </code></pre> <p>home.php</p> <pre><code> &lt;?php error_reporting(0); session_start(); if(!isset($_SESSION['stuName'])) { echo "Click here to &lt;a href=\"index.php\"&gt;Re-LogIn&lt;/a&gt;"; } else if(isset($_POST['logout'])) { unset($_SESSION['stuName']); header('Location: index.php'); } else if(isset($_POST['edit'])) { header('Location: edit.php'); } ?&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;?php if (isset($_SESSION['stuName'])) { ?&gt; &lt;form id="studenthome" action="studenthome.php" method="post"/&gt; &lt;div id="menubar"&gt; &lt;input type="submit" name="logout" value="Logout" /&gt; &lt;input type="submit" name="edit" value="Edit Profile" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>upto this everything is working fine.</p> <p>edit.php</p> <pre><code> session_start(); if(!isset($_SESSION['stuName'])) { echo "Click here to &lt;a href=\"index.php\"&gt;Re-LogIn&lt;/a&gt;"; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload