Jump to content

[SOLVED] session + isset problems


chocopi

Recommended Posts

ok, so when i log in my sessions are meant to be carried across from this page:

 

<?php
if(isset($_POST["submit"]))
{
	if ($login_check > 0)
	{
		$_SESSION['id'] = "$id";
		$_SESSION['username'] = "$username";
		$_SESSION['password'] = "$password";
		$filename = "login_check.php";
		ob_end_clean();
		header("Location: ".$filename);
	} else
		{
			$errors++;
		}
}
?>

 

That goes through a page to this. So either the sessions are wrong or this isset is wrong as it redirects even when its not meant to.

 

<?php

// Start Session
session_start();

require_once('page_header.php');

// Declare Variables
$id = $_SESSION['id'];
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$title = 'Chocopi :: Main';

if(isset($id, $username, $password))
{
$filename = "index.php";
header("Location: ".$filename);
} else
	{
		echo "".$username."(#".$id.")";
	}

?>

 

So if you can point out my mistakes, many thanks

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/
Share on other sites

it is there i just didnt post it  :-[

 

<?php

ob_start();

session_start();


	// Variables
	$username = $_POST['username'];
	$raw_password = $_POST['password'];
	$password = md5($raw_password);
	$login = mysql_query("SELECT id FROM Mark WHERE username='$username' && password='$password'");
	$login_check = mysql_num_rows($login);
	$row = mysql_fetch_array($login, MYSQL_ASSOC);
	$id = $row['id'];

if(isset($_POST["submit"]))
{
	if ($login_check > 0)
	{
		$_SESSION['id'] = "$id";
		$_SESSION['username'] = "$username";
		$_SESSION['password'] = "$password";
		$filename = "login_check.php";
		ob_end_clean();
		header("Location: ".$filename);
	} else
		{
			$errors++;
		}
}

ob_flush();

?>

 

Cheers,

 

~ Chocopi

<?php
// Declare Variables
$id = $_SESSION['id'];
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$title = 'Chocopi :: Main';

if(isset($id, $username, $password))

?>

 

OK lets look at this

$id gets SET to $_SESSION['id']

thus they ARE set even if $_SESSION['id'] = null (nothing);

 

you need to isset($_SESSION['id']) or !empty($id) or even is_null($id)

you should work that out for yourself but personally i do the following

 

<?php
if( isset($_SESSION['id']) && isset($_SESSION['username']) && isset($_SESSION['password']) )
?>

 

also remember

session_start();

mus be used in all pages that use $_SESSION

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.