Jump to content

$_session Difficulties


chibineku
 Share

Recommended Posts

I am trying to create a login script that will set $_SESSION["userid"] to the value of a field in my database, called id. This should be very simple, but for some reason isn't working. Here is my login script:

<?phpsession_start();include_once("db_include.php5");doDB();//check for required fields from the formif ((empty($_POST['username']) && empty($_POST['email'])) || empty($_POST['password'])) {header("Location: loginform.php5");exit;}   else if($_POST["username"] && $_POST["password"]){	//create and issue the query	$sql = "SELECT id FROM aromaMaster WHERE username='".$_POST["username"]."' AND password=PASSWORD('".$_POST["password"]."')";	$sql_res =mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));	//get the number of rows in the result set; should be 1 if a match	if(mysqli_num_rows($sql_res) != 0) {	  //if authorized, get the userid	  while($info = mysqli_fetch_array($sql_res)) {		$userid = $_info["id"];	  }	  //set session variables	  $_SESSION["userid"] = $userid;	  mysqli_free_result($sql_res);	  //redirect to main page	  header("Location: loginredirect.php5");	  exit; }	} else if($_POST["email"] && $_POST["password"]) {		  //create and issue the query	$sql = "SELECT id FROM aromaMaster WHERE email='".$_POST["email"]."' AND password=PASSWORD('".$_POST["password"]."')";	$sql_res =mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));	//get the number of rows in the result set; should be 1 if a match	if(mysqli_num_rows($sql_res) != 0) {	  //if authorized, get the userid	  while($info = mysqli_fetch_array($sql_res)) {		$userid = $_info["id"];	  }	  //set session variables	  $_SESSION["userid"] = $userid;	  mysqli_free_result($sql_res);	  //redirect to main page	  header("Location: loginredirect.php5"); 	  exit;}	  } else {	  //redirect back to login form	  header("Location: loginform.php5");	  exit;	}	mysqli_close($mysqli);?>

I am echoing the session_id() and trying to echo $_SESSION["userid"] on the page that the user is redirected to, called contact.php5, but only the session id shows up.

Link to comment
Share on other sites

Fixed, la la la

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...