Reply
Login Script Problem
Old 03-08-2008, 12:25 PM Login Script Problem
Gilligan's Avatar
Dead Like Me

Posts: 1,618
Name: Stefan
Location: London, UK
I have this login script, and when the user fills in username and password it takes them to login.php and tells them the login was successful. But even if you type in url.com/login.php in the browser it will say the login was successful, so i want to make it so only if the referrer page is a, b, or c etc. then it will display this message.

So i tried this

PHP Code:
<?php

ob_start
();

include(
"config.php"); 

// connect to the mysql server 
$link mysql_connect($server$db_user$db_pass
or die (
"Could not connect to mysql because ".mysql_error()); 

// select the database 
mysql_select_db($database
or die (
"Could not select database because ".mysql_error()); 

$match "select id from $table where username = '".$_POST['username']."' 
and password = '"
.$_POST['password']."';"

$qry mysql_query($match
or die (
"Could not match data because ".mysql_error()); 
$num_rows mysql_num_rows($qry); 

if (
$num_rows <= 0) { 
echo 
"Sorry, there is no username $username with the specified password.<br>"
echo 
"<a href=login.html>Try again</a>"
exit; 


elseif (
$_SERVER['HTTP_REFERER'] != 'http://sgilligan.co.uk/2/index.php' || $_SERVER['HTTP_REFERER'] != 'http://www.sgilligan.co.uk/2/index.php' || $_SERVER['HTTP_REFERER'] != 'http://sgilligan.co.uk/2/' || $_SERVER['HTTP_REFERER'] != 'http://www.sgilligan.co.uk/2/'|| $_SERVER['HTTP_REFERER'] != $phpself) {
   
  echo
'

<html>

whatever here

</html>

'
;
      exit; }

else { 

setcookie("loggedin""TRUE"time()+(3600 24));
setcookie("mysite_username""$username");
echo 
"Thank you $username, You are now logged in!<br>"
echo 
"Continue to the <a href=members.php>members</a> section."
}

ob_end_flush();


?>
But it won't work, it shows the html code even if the referrer is one of the list in the code. (aka shows the html code every time, regardless of the referrer)
Gilligan is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 03-08-2008, 11:53 PM Re: Login Script Problem
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,005
Name: Jeremy Miller
Location: Reno, NV
I wouldn't use referrers -- some browsers hide referrers or have referrers turned off. Instead, try adding a check for your cookie variables and showing success only if the cookies exist and are properly set.

BTW: Your setup is easy to hack -- All I'd have to do is change the cookie for mysite_username to any other username and I'd be granted access. You may want to go with session values or check that thread on here which talks about persistent logins.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Login Script Problem
 

Thread Tools

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


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

 


Page generated in 0.11009 seconds with 12 queries