hatrickpatrick Posted August 30, 2007 Share Posted August 30, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/ Share on other sites More sharing options...
Fadion Posted August 30, 2007 Share Posted August 30, 2007 How are $uname and $loginhash passed to the function? Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338046 Share on other sites More sharing options...
teng84 Posted August 30, 2007 Share Posted August 30, 2007 yah add a parameter for this auth() take note that php is not OOP so you cant have those value but you can use the post data session and get variables inside your function without having them in your pram. ;D Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338047 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Uhm PHP can handle OOP. None of that sentence makes sense. You need to either pass the variables as arguments or make them global. Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338054 Share on other sites More sharing options...
teng84 Posted August 30, 2007 Share Posted August 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338056 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 The code has nothing to do with post or get! It's about a function, and the programmer not knowing enough about variable scope. Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338060 Share on other sites More sharing options...
teng84 Posted August 30, 2007 Share Posted August 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338063 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/67309-can-someone-tell-me-why-my-auth-function-isnt-working/#findComment-338142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.