Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php login script not working
Old 11-21-2010, 05:43 AM php login script not working
Skilled Talker

Posts: 77
Name: adam
Location: UK
Trades: 0
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.

checklogin - does the checking
PHP Code:
<?php

include("connect.php");

$email $_POST["email"];
$password $_POST["password"];


$password md5($password);

$sql "SELECT * FROM numbers";
$result mysql_query($sql);


while (
$row3 mysql_fetch_array($resultMYSQL_ASSOC))
{
    if((
$password == $row3["password"]) && ($email == $row3["email"]))
    {

        
$_SESSION["userid"] = $row3["id"];
        
header ('Location: control_panel.php');
        
        
//debug
        //echo $password;
        //$useridvar = $_SESSION["userid"];
        //echo $useridvar;
    
}

    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.
******************************************
*/


?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
mintuz is offline
Reply With Quote
View Public Profile Visit mintuz's homepage!
 
 
Register now for full access!
Old 11-21-2010, 09:54 AM Re: php login script not working
Banned

Posts: 408
Name: mushget
Trades: 0
you can try to add session_register("userid");before you using the session
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
Old 11-21-2010, 10:42 AM Re: php login script not working
Skilled Talker

Posts: 77
Name: adam
Location: UK
Trades: 0
still having the same problem
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
mintuz is offline
Reply With Quote
View Public Profile Visit mintuz's homepage!
 
Old 11-21-2010, 11:48 AM Re: php login script not working
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-21-2010, 12:21 PM Re: php login script not working
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by mushget View Post
you can try to add session_register("userid");before you using the session
session_register is deprecated as of PHP 5.3 and according to the documentation:
Quote:
Use of $_SESSION is preferred, as of PHP 4.1.0
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-22-2010, 12:28 AM Re: php login script not working
sean1984's Avatar
Novice Talker

Posts: 9
Name: sean chow
Location: china
Trades: 0
PHP Code:
 <?php 
session_start
();
include(
"connect.php"); 

$email $_POST["email"]; 
$password $_POST["password"]; 


$password md5($password); 

$sql "SELECT * FROM numbers"
$result mysql_query($sql); 


while (
$row3 mysql_fetch_array($resultMYSQL_ASSOC)) 

    if((
$password == $row3["password"]) && ($email == $row3["email"])) 
    { 

        
$_SESSION["userid"] = $row3["id"]; 
        
header ('Location: control_panel.php'); 
        exit(); 
    } 

    if (
$_SESSION["userid"]==""
    { 
        
header ('Location: login.php'); 
        exit(); 
    } 



?>
__________________
icq#: 637540642
msn:
Please login or register to view this content. Registration is FREE
sean1984 is offline
Reply With Quote
View Public Profile
 
Old 11-22-2010, 02:44 AM Re: php login script not working
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Sean's approach suffers from the same problems I mentioned above, including the problem the OP reported to begin with.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-22-2010, 06:37 AM Re: php login script not working
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Quote:
Originally Posted by NullPointer View Post
2. md5 is not a password hashing function.
it isn't?
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 11-22-2010, 12:37 PM Re: php login script not working
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Lashtal View Post
it isn't?
Nope.

Md5 is useful for checking file integrity, but as a password hashing algo it hasn't been viable for a long time. http://en.wikipedia.org/wiki/Md5#Col...ulnerabilities

Using sha1 with a salt would be better, but still not ideal.

Personally I'd recommend sha2 algos, such as sha256.

PHP Code:
$password;
$salt;

$hash hash'sha256'hash('sha256'$password) . $salt ); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-22-2010 at 12:38 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-22-2010, 06:26 PM Re: php login script not working
Extreme Talker

Posts: 156
Trades: 0
If you use the error reporting function; error_reporting(E_ALL, ~E_Notice); it should give you a better clue as to what is happeninf
dagaul101 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php login script not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.46465 seconds with 12 queries