Jump to content

session passed login script requiring me to login twice


cooldude832

Recommended Posts

I have a login that uses a session activation to make users login.  This is the code

<?php
$start = session_start();
$ob = ob_start();

// Recreation of variables for later encryption uses the $_POST  will be replaced with the decrypted source
$username = trim($_POST['username']);
$password =  trim($_POST['password']);
$cryptpassword = md5($password);
$url =  trim($_POST['url']);


//Connects to DB
require("includes/mysql_include.php");

$table = "users";
$sql="SELECT * FROM $table WHERE Username='$username' and Password='$cryptpassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
$storage=  mysql_fetch_array($result);


// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['loggedon'] = "yes";
$_SESSION['user'] = $username;
$_SESSION['firstname'] = $storage['Firstname'];
header("location: $url");
}
else 	
{
echo "Wrong Username or Password";
}

 

the page it returns to has this at the top to check if logged in:

session_start();
if (ISSET($_SESSION['loggedon'])) 
{$view = "login";}

I think my issue is that the page is sending headers and therefor session aren't starting any tips?

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.