Coming soon - Get a detailed view of why an account is flagged as spam!
view details
1
[PHP] Having a problem with my log in and sessions.
Author Summary
jtrot91 is in PHP
Post Body

I am making a website for my final for my scripting class. Until yesterday the login was working correctly. I cleared cookies in my browser (Chrome) but that still shouldn't cause it to break in other browsers (Firefox) or other machines. So I'm assuming something is wrong in the code. My code works like this, which I have used basically for other websites for class that have worked fine. First is index.php which is just this

<?php
 require_once 'includes/init.php'; 
?>

and a call to a function to make it load everything on that page (index.php?content=whatever) init.php (which I copied from our book and have been using has this.

require_once 'includes/functions.php';
require_once 'includes/database.php';
session_start();

functions.php just has the load content function, and database.php is just to connect to the database. Login.php is just a simple form that goes to checklogin.php which has this

<?php
$username = $_POST["username"];
$password = $_POST["password"];

$check = mysql_query("SELECT * FROM users WHERE user = '" . $username . "'");

if($check === FALSE) 
{
    die(mysql_error()); 
}
$result = mysql_fetch_array($check);

if ($result['password'] == $password)
{
    echo "Login successful";
    $_SESSION['loggedIn'] = 1;
    echo "<script>location.href='index.php?content=frontPage'</script>";

?>
<meta HTTP-EQUIV="REFRESH" content="0; url=index.php?content=frontPage">
<?php
}
else
{
    echo "Login unsuccessful";
    echo "<br>";
    echo "<a href='index.php?content=login'>Try Again</a>";
}   
?>    

Does anyone know the problem or why it just stopped working? Or just a different way of doing this? The problem seems to be that when I put a "echo session_id();" on different pages, every time it loads another page the session id will change.

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
79,784
Link Karma
15,292
Comment Karma
64,188
Profile updated: 1 week ago
Posts updated: 10 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 years ago