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
https://forums.phpfreaks.com/topic/32303-please-help-with-code/
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
https://forums.phpfreaks.com/topic/32303-please-help-with-code/#findComment-149949
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
https://forums.phpfreaks.com/topic/32303-please-help-with-code/#findComment-149993
Share on other sites

best suggestion is to step through the entire process. have it echo results back so you know what's going on. You'll probably also need to include things like [code=php:0]echo mysql_error();[/code] to make sure you're getting results.
Link to comment
https://forums.phpfreaks.com/topic/32303-please-help-with-code/#findComment-150028
Share on other sites

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.