PHP user authocation function has a bug

Post Reply
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

PHP user authocation function has a bug

Post by Rksk » Thu May 27, 2010 1:07 pm

hi,

pls tell me, what is the bug in below php function?

Code: Select all


ob_start();session_start();
$hostname = "***********";
$data_username = "********"; //database username
$data_password = "*******"; //database password
$data_basename = "**********"; //database name
$conn = mysql_connect("".$hostname."","".$data_username."","".$data_password."");  
mysql_select_db("".$data_basename."") or die(mysql_error());  


start()


function start() {
if(isset($_COOKIE['eku']) AND isset($_COOKIE['ekp'])){

        $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_COOKIE['eku']."'"));
      $password = $fetch_users_data->password;
      $username = $fetch_users_data->username;

        if ($_COOKIE['ekp'] != md5($password)) {
        echo "Hi Guest,<br><br>";
        return;
        }
    } else {
        echo "Hi Guest,<br><br>";
        return;
        }



echo "Hi ".$username.",<br>";

if(isset($_COOKIE['eklastVisit'])){
    $visit = $_COOKIE['eklastVisit']; 
echo "Your last visit was - ". $visit."<br><br>";
}
$inTwoMonths = 60 * 60 * 24 * 60 + time(); 
setcookie('eklastVisit', date("G:i - m/d/y"), $inTwoMonths); 

}
 


Thankz.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: PHP user authocation function has a bug

Post by Neo » Fri May 28, 2010 9:34 am

There was a missing parameter in function mysql_select_db. I have also removed unnecessary double quotes that used to concatenate. Try this and let me know how it goes.

Code: Select all

$conn = mysql_connect($hostname, $data_username, $data_password);
mysql_select_db($data_basename, $conn) or die(mysql_error());
 
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: PHP user authocation function has a bug

Post by Rksk » Fri May 28, 2010 12:28 pm

Hi,

ur correction is ok.


but the bug is in the function start. Can u find it?

thankz.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: PHP user authocation function has a bug

Post by Neo » Sat May 29, 2010 3:51 am

There is another silly bug I can see. Function call "start()" must end up with a semicolon.
So correct it as start();

As a practice, I usually define the function on top of the calling point in general programming. Since PHP too is based on C/C++ syntaxes, I would like to suggest that here.
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: PHP user authocation function has a bug

Post by Rksk » Sat May 29, 2010 8:32 pm

Thankz neo.
it's working.

i'm developing a mobile forum for my mobile site. above fuction is a part of it. i will ask you for future help.

thankz.
Post Reply

Return to “PHP & MySQL”