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
Old 03-08-2008, 11:25 AM Login Script Problem
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
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
 
 
Register now for full access!
Old 03-08-2008, 10:53 PM Re: Login Script Problem
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Login Script Problem
 

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 0.22581 seconds with 12 queries