GameYin Posted March 27, 2008 Author Share Posted March 27, 2008 I completely lose ya there bud. I think your right...I don't think register.php will help you, it only inserts into database...I will give you full login.php Then you can make the assumption yourself.. <?php ob_start(); $host="localhost"; // Host name $username="gameyinc"; // Mysql username $password="*****"; // Mysql password $db_name="gameyinc_members"; // Database name $tbl_name="users"; // Table name $user=$_POST['username']; $link = mysql_connect("$host", "$username", "$password")or die(mysql_error()); mysql_select_db("$db_name")or die("cannot select DB") or die ("Could not connect to mysql because ".mysql_error()); $match = "select id from $tbl_name 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; } else { setcookie("loggedin", "TRUE", time()+(3600 * 24)); setcookie("mysite_username", "$user"); echo "You are now logged in!<br>"; echo "Continue to the <a href=\"index.php\">Home</a> Page."; } ob_end_flush(); ?> Here is logout.php since it uses cookies too. <?php // expire cookie setcookie ("loggedin", "", time() - 3600); echo "You are now logged out.<br>"; echo "<a href=\"login.html\">Log in</a> Or go to the home page, <a href=\"index.php\">Home</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502269 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 Humm code should be ok if their on different pages (unless you click back, instead of the link) would need to see the index.php page and know the problem a little better Just better point this out update the code (see below) as your login is vulnerable to an SQL injection exploit (anyone can login as anyone or even change other peoples password, drop the database etc) you could also hash the password (we're come back to that) (seach this forum for MD5 your find a ton of stuff) <?php ob_start(); $host="localhost"; // Host name $username="gameyinc"; // Mysql username $password="*****"; // Mysql password $db_name="gameyinc_members"; // Database name $tbl_name="users"; // Table name $user=$_POST['username']; $link = mysql_connect("$host", "$username", "$password")or die(mysql_error()); mysql_select_db("$db_name")or die("cannot select DB") or die ("Could not connect to mysql because ".mysql_error()); //****Add this $uName = mysql_escape_string($_POST['username']); $uPass = mysql_escape_string($_POST['password']); //**$match = change to this $match = "select id from $tbl_name where username = '$uName' and password = '$uPass';"; $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; ..not needed } else { setcookie("loggedin", "TRUE", time()+(3600 * 24)); setcookie("mysite_username", "$user"); echo "You are now logged in!<br>"; echo "Continue to the <a href=\"index.php\">Home</a> Page."; } ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502284 Share on other sites More sharing options...
GameYin Posted March 27, 2008 Author Share Posted March 27, 2008 index.php just displays the 2 links, depending on the cookie, nothing really there... anyway for sessions dont u need session_start? What page is the code you listed for? login.php? Code worked, still doesn't help with the refresh issue. I still think it has something to do with the cookies.... Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502290 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 I just created an account (tester) it seams to be ok, (unless i use the back button) so you could use a metatag redirect ie <?php echo "You are now logged in!<br>"; echo "Continue to the <a href=\"index.php\">Home</a> Page."; ?> to <?php $url = "index.php"; $time = 5; echo "<html><head> <title>Logged in</title> <META http-equiv=\"refresh\" content=\"$time;URL=$url\"> </head> <body> <center>You will be redirected automatically in $time seconds. or click <a href=\"$url\">here</a> </center></body></html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502302 Share on other sites More sharing options...
GameYin Posted March 27, 2008 Author Share Posted March 27, 2008 I know you created an account called tester.. www.gameyin.com/list.php Anyway...the code right now, am I using sessions? session_start...? ..ok I will put that Also, I guessed testers' password, very original Also that doesn't work, maybe I should put the meta refresh (in what I think I heard before was a sleep mode of some kind?) Anyway should I do that "sleep mode" thing for 2 seconds then call the meta refresh? Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502308 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 the thing is, i got to http://www.gameyin.com/index.php click login enter the username & password then click 'Home' and everything seams okay! are you getting something different ? if you click back, then that will cause the problem Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502318 Share on other sites More sharing options...
GameYin Posted March 27, 2008 Author Share Posted March 27, 2008 Once it goes to login.php, and then it says continue to home page, i click that, and it still displays index.php as if nothing happened....Does anyone else see what I'm seeing? If it's just me then I guess something is wrong with my cache, I'll ignore it.....?? Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502338 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 i'm using firefox,, i just tried with IE7 and ..its fine.. if someone else can test http://www.gameyin.com/index.php user = tester pass = tester Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502349 Share on other sites More sharing options...
truck7758 Posted March 27, 2008 Share Posted March 27, 2008 seems fine to me using firefox Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502373 Share on other sites More sharing options...
GameYin Posted March 27, 2008 Author Share Posted March 27, 2008 Try Opera, that's what I'm using. If everyone else thinks it is ok I will just ignore it. EDIT: It works in FF and IE6....weird Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502437 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 try adding the path to the cookies Add , "/" ie setcookie("loggedin", "TRUE", time()+(3600 * 24), "/"); setcookie("mysite_username", "$user", "/"); Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502448 Share on other sites More sharing options...
GameYin Posted March 27, 2008 Author Share Posted March 27, 2008 Thanks for it. I have an error now, go try logging in. setcookie("loggedin", "TRUE", time()+(3600 * 24), "/"); setcookie("mysite_username", "$user", "/"); echo "You are now logged in!<br>"; echo "Continue to the <a href=\"index.php\">Home</a> Page."; Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502451 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 oops setcookie("loggedin", "TRUE", time()+(3600 * 24), "/"); setcookie("mysite_username", "$user", time()+(3600 * 24),"/"); //updated 3rd = expire, 4th = path echo "You are now logged in!<br>"; echo "Continue to the <a href=\"index.php\">Home</a> Page."; Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502473 Share on other sites More sharing options...
GameYin Posted March 28, 2008 Author Share Posted March 28, 2008 Ok thanks it worked. Anything else you would recommend before I stop coming here to this thread? Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502689 Share on other sites More sharing options...
MadTechie Posted March 28, 2008 Share Posted March 28, 2008 erm.. if you intrested.. read up on session (if you get stuck swapping cookies for sessions start a new thread) maybe read into the isset() function and $_POST and combine to have the login.php and logout.php script contained in the same file.. other than that i think we're done Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-502708 Share on other sites More sharing options...
GameYin Posted March 28, 2008 Author Share Posted March 28, 2008 Ok, I will read up on some session stuff. I'll get back to you. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/98159-connecting-to-database/page/2/#findComment-503247 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.