Note that there are some explanatory texts on larger screens.

plurals
  1. POsession management: problem displaying username in the header
    text
    copied!<p>I am working on a simple login and logout module for my website without any security. I am using wamp on a windows xp machine. I am creating session when a user submits the login informaton it redirects to a process.php file which creates the session variables and starts session. Now if the login is successful user is redirected to the welcome page which includes a header file(which displays the header involving signin logout help options) The problem is the header is not changing the signin link to logout as the user logs successfully. The below code is from process.php which initiates a login.</p> <pre><code>$username = $_POST['username']; $password = $_POST['password']; //echo "{$username}:{$password}"; $connection = mysql_connect("localhost","root",""); if(!$connection) { die("Database Connection Failed".mysql_error()); } $db_select = mysql_select_db("tester",$connection); if(!$db_select) { die("Database Selection Failed".mysql_error()); } $result = mysql_query("SELECT * FROM user",$connection); if(!$result) { die("Database Selection Failed".mysql_error()); } $q = "SELECT * FROM user " ."WHERE Name='".$username."' AND Password='".$password. "' "; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { session_start(); // Login good, create session variables $_SESSION["valid_id"] = session_id(); $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); Header('Location: welcome.php'); </code></pre> <p>The following code is from header.php which is included in welcome.php</p> <p> </p> <pre><code> &lt;/div&gt; &lt;div id = "userdetail"&gt; &lt;?php if(isset($_SESSION["valid_user"])) { echo($_SESSION["valid_user"]." " ); echo("&lt;a href=logout.php&gt;Logout&lt;/a&gt;"); } else { echo("&lt;a href = login.php&gt;Sign In&lt;/a&gt;"); } ?&gt; | Help | Search &lt;input type = "text" name = "searchbox" value = "" /&gt; &lt;/div&gt; &lt;/div&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