Jump to content

[SOLVED] $_session['uid'] doesn't stay open


dachshund

Recommended Posts

hi,

 

i have this code in the header of my page

<?php

if (isset($_SESSION['uid'])){
echo "Hello";
}else {
include $_SERVER['DOCUMENT_ROOT'] . "/test/profile/login.php";
}
?>

 

and my login.php looks like this

 


<?php
      
  if(!$_POST['submit'] == 'login'){
      echo "<div id=\"blanket\" style=\"display:none;\"></div>\n";
  echo "<div id=\"popUpDiv\" style=\"display:none;\">\n";
  echo "<a href=\"#\" onclick=\"popup('popUpDiv')\">\n";
  echo "Close\n";
  echo "</a>\n";
  echo "<div id=\"loginform\">\n";
  echo "<form name=\"login\" method=\"post\" action=\"#\">\n";
  echo "<p>Username\n";
  echo "<input name=\"username\" type=\"text\" class=\"formtext\" id=\"username\" size=\"28\">\n";
  echo "</p>\n";
  echo "<p>Password\n";
  echo "<input name=\"password\" type=\"password\" class=\"formtext\" id=\"password\" size=\"28\">\n";
  echo "</p>\n";
  echo "<input type=\"submit\" name=\"submit\" class=\"loginformtext\" value=\"Submit\">\n";
  echo "</form>\n";
  echo "</div>\n";
  echo "</div>\n";
  echo "<span class=\"login_text\"><a href=\"#\" onclick=\"popup('popUpDiv')\">LOG IN</a> |\n";
  
   }else {
  $user= $_POST['username'];
  $pass= $_POST['password'];
  
  	if($user && $pass){
		$sql = "SELECT * FROM `users` WHERE `username`='$user'";
		$res = mysql_query($sql) or die(mysql_error());

			if(mysql_num_rows($res) == 1){
				$epass = md5($password);
		    	$sql2 = "SELECT * FROM `users` WHERE `username` ='$user' AND `password`='$epass'";
				$res2 = mysql_query($sql2) or die(mysql_error());

			    	if(mysql_num_rows($res2) ==1){
					//success
					$row = mysql_fetch_assoc($res2);
					$_SESSION['uid'] = $row['id'];
					echo "<span class=\"login_text\">ACCOUNT | <a href=\"\n";
					include $_SERVER['DOCUMENT_ROOT'];
					echo "/test/profile/logout.php\">LOGOUT</a></span>\n";
					}else {
					echo "<span class=\"login_text\">USERNAME OR PASSWORD INCORRECT | <a href=\"/phptesting\">HOME</a></span>\n";
					}
			}else {
			echo "<span class=\"login_text\">USERNAME OR PASSWORD INCORRECT | <a href=\"/phptesting\">HOME</a></span>\n";
			}
	}else {
	echo "<span class=\"login_text\">PLEASE SUPPLY ALL VALID FIELDS | <a href=\"/phptesting\">HOME</a></span>\n";
	}
}

?>

 

 

it logs in fine initially, but as soon as i click a link to go to another page the session is lost.

 

can anyone see why?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/
Share on other sites

You should actually be developing and debugging php code on a system where those two settings are set in your php.ini so that fatal parse errors would be displayed as well. It will save you a lot of time. Stop and start your web server to get any change made to php.ini to take effect and confirm the settings were changed using a phpinfo() statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.