thisisnuts123 Posted November 4, 2007 Share Posted November 4, 2007 Hello guys, I have got the register page and login page to work. only problem is users can just type url/main.php and bypass the login page what script do i need to include in there to make sure user logs in Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 4, 2007 Share Posted November 4, 2007 You need to use sessions or cookies to make login pages 'valid' or 'invalid'. Your script should do the checks, and then deliver the page to valid users, or deny to anyone else. Read the PHP Freaks tutorials on how to accomplish this. PhREEEk Quote Link to comment Share on other sites More sharing options...
thisisnuts123 Posted November 4, 2007 Author Share Posted November 4, 2007 kk thanks!! Quote Link to comment Share on other sites More sharing options...
thisisnuts123 Posted November 4, 2007 Author Share Posted November 4, 2007 hey so i found the following tutorial http://www.phpfreaks.com/tutorials/17/1.php can i make this work with my script? <?php $connection = mysql_connect(localhost', ''username, 'pass'); $password = $_POST[password]; $pass = md5($password); $db = mysql_select_db('game', $connection); $sql = "SELECT id FROM user WHERE username='$_POST[username]' AND password='$pass'"; $result = mysql_query($sql); $num = mysql_num_rows($result); if ($num > 0) { //USER AND PASS ARE CORRECT $id = mysql_fetch_assoc($result); setcookie("auth", "yes", time()+3600); setcookie("id", $id['id']); setcookie("username", $id['username']); header ("Location: main.php"); }else { header ("Location: incorrect.php"); }; ?> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 4, 2007 Share Posted November 4, 2007 All of the Tutorials on PHP Freaks have been pretty thoroughly tested, and seem to work well on a majority of server configurations, but of course YMMV is in full effect. Also, these Tutorials are examples, and written with very simplistic, if not insecure in some cases, coding. You should use the code to 'guide you' on getting it integrated with your existing code. Once you have it doing what you expect, then appropriately 'harden' it for security concerns. PhREEEk Quote Link to comment 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.