Jump to content

Can someone tell me why my auth() function isn't working?


hatrickpatrick

Recommended Posts

This is a function to check if the username & pass stored in a cookie match the database entry for the account:
[code]
function auth()
{
$decryptedpass=decrypt($uname,$loginhash);
$sqlauth="SELECT * FROM users WHERE user_pass='$loginhash'";
$resultauth=mysql_query($sqlauth);
echo $uname;
if (@mysql_num_rows($resultauth)==0)
  {
   return false;
  }
if (@mysql_num_rows($resultauth)>0)
  {
   return true;
  }
}

 

That is an included file. In the main file, index.php, I have this:

 

if (!auth())

{

echo "You are not logged in";

}

if (auth())

{

echo "You are logged in";

}

[/code]

 

It ALWAYS tells me I am not logged in, even though later in the file I exho $uname and $loginhash and they are both displayed correctly, and matching their respective DB fields...

 

Can anyone shed some light on this?

Uhm PHP can handle OOP. None of that sentence makes sense.

 

You need to either pass the variables as arguments or make them global.

 

sorry ok

php is not OOP but can handle OOP

2nd GET, POST, SESSION are global variables so they dont need to be declared as global and can be called any where

 

 

sorry for bad English  ;D ;D ;D

yah but look carefully the function this only need one value which is the $UNAME RIGHT?

wich i believe from a post data so i guess no need to add a parameter

 

and wait what are this line for

$decryptedpass=decrypt($uname,$loginhash);

 

function ends without using this $decryptedpass

LOL weird

 

 

This is a function to check if the username & pass stored in a cookie match the database entry for the account.

 

teng84, we're talking about cookies :)

 

Obviously the function needs arguments:

 

function auth($uname){
$decryptedpass=decrypt($uname,$loginhash);
//rest of code
}
auth($_COOKIE['username']);

 

Smth like that. Is there a decrypt() function in php as i cant find it in the manual? Probably its a custom one.

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.