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
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

Link to comment
Share on other sites

<?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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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