So i am creating a website with login facility and I want the user to be redirected to a page if the details entered match the info in the database. However it is not working. everytime i submit the info it just redirects me to previous page ( should do if details are wrong ). The password and email are correct I have done some debugging for that. it must lay with the sessions. Here is my code.
if ($_SESSION["userid"]=="")
{
header ('Location: login.php');
//echo "hi";
}
}
?>
control_panel is the page the user should get directed too after a sucessful login. I dont really want to give you the whole page because its for a project I am working on and do not want to get in trouble for copyright. This is basically at the very top of the page.
PHP Code:
<?php
if ($_SESSION["userid"]=="")
{
header ('Location: login.php');
}
include('connect.php');
/*
Copyright 2010-2011 All Rights Reserved.
******************************************
*/
There are several things wrong with this script in addition to what is causing your problem:
1. You are wide open for a sql injection
2. md5 is not a password hashing function. Use something that is more resistant to collisions like sha1. Also, use a salt.
3. Don't select the entire table and then manually search through the results.
You're problem is being caused by #3. You're checking the email and password against every user in the database. However, you are redirecting back to login.php as soon as you find a user that does not match.