Jump to content

Please help with code!!


forumnz

Recommended Posts

Ok, I have a password verification script. When someone tries to get to the index.php they are taken straight to Login.php so they can login. When they enter their details in goes to loginaction.php and checks it against the database I have.

Except the problem is when it checks it, it goes straight back to he login page prompting to login again. I have put the script below. Please help. Note: I have changed password in example.

[code]<?php
// Check if the information has been filled in
if($psEmail == '' || $psPassword == '') {

// No login information
header('Location: Login.php?refer='.urlencode($psRefer));

} else {

// Authenticate user
$hDB = mysql_connect('localhost', 'php', 'passord');
mysql_select_db('my_db', $com);

$sQuery = "
Select iUser, MD5(UNIX_TIMESTAMP() + iUser + RAND(UNIX_TIMESTAMP())) sGUID
From tblUsers
Where sEmail = '$psEmail'
And sPassword = password('$psPassword')";

$hResult = mysql_query($sQuery, $hDB);

if(mysql_num_rows($hResult)) {

$aResult = mysql_fetch_row($hResult);

// Update the user record
$sQuery = "
Update tblUsers
Set sGUID = '$aResult[1]'
Where iUser = $aResult[0]";

mysql_query($sQuery, $hDB);

// Set the cookie and redirect
setcookie("session_id", $aResult[1]);

if(!$psRefer) $psRefer = 'index.php';
header('Location: '.$psRefer);

} else {

// Not authenticated
header('Location: Login.php?refer='.urlencode($psRefer));

}
}
?> [/code]
Link to comment
Share on other sites

I dont' see your index page here... is it checking for that cookie that login is setting?

Also, your login form is open to [url=http://us3.php.net/manual/fi/security.database.sql-injection.php]SQL Injection Attacks[/url]. You need to excape any content coming from an untrusted source (like unknown web site visitors) using [url=http://us3.php.net/mysql_real_escape_string]mysql_real_escape_string()[/url]
Link to comment
Share on other sites

and incSession.php leads to:

[code]<?php
// Check for a cookie, if none got to login page
if(!isset($HTTP_COOKIE_VARS['session_id'])) {
header('Location: Login.php?refer='.urlencode($PHP_SELF.'?'.$HTTP_SERVER_VARS['QUERY_STRING']));
}

// Try to find a match in the database
$sGUID = $HTTP_COOKIE_VARS['session_id'];
$hDB = mysql_connect('server', 'username', 'password');
mysql_select_db('database', $hDB);

$sQuery = "
Select iUser
From tblUsers
Where sGUID = '$sGUID'";

$hResult = mysql_query($sQuery, $hDB);

if(!mysql_num_rows($hResult)) {
// No match for guid
header('Location: Login.php?refer='.urlencode($PHP_SELF.'?'.$HTTP_SERVER_VARS['QUERY_STRING']));
}
?> [/code]
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.