doddsey_65 Posted November 18, 2009 Share Posted November 18, 2009 Okay i used this script http://php.about.com/od/finishedphp1/ss/php_login_code.htm to crete my system. everything worked last night hence the solved topic. But now it isnt. when i login the screen doesnt display anything bar my header and content holder. I have worked out why by trial and error. I use the include statement to include my header and main page before the content. I am doing: <?php include('header.php'); include('contentholder.php'); ?> When i only use one of these it works fine, but when i use both of them it breaks. I do however need both of them for the page to display properly. Any idea why this is happening? I can post my heder and content gholder scripts if tht helps. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/ Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 Yes, post both of the scripts as it is hard to debug this without seeing code. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960133 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 okay here is the login script: <?php include'header.php'; include'contentholder.php'; // Connects to your Database mysql_connect("localhost", "myuser", "mypass") or die(mysql_error()); mysql_select_db("mydb") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: index.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username'])or die(mysql_error()); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour)or die(mysql_error()); setcookie(Key_my_site, $_POST['pass'], $hour)or die(mysql_error()); //then redirect them to the members area header("Location: index.php")or die(mysql_error()); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> here is header.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb"> <head> <title>Blender 101 | Home</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-language" content="en-gb" /> <meta http-equiv="content-style-type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="resource-type" content="document" /> <meta name="distribution" content="global" /> <meta name="copyright" content="2000, 2002, 2005, 2007 phpBB Group" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" href="stylesheet.css" type="text/css" /> <link rel="stylesheet" href="css/gallery.css" type="text/css" media="screen" charset="utf-8" /> <script src="scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script> <script src="scripts/mootools-1.2-more.js" type="text/javascript"></script> <script src="scripts/jd.gallery.js" type="text/javascript"></script> <script src="scripts/jd.gallery.transitions.js" type="text/javascript"></script> <link rel="icon" type="image/gif" href="images/favicon.gif"> </head> <body> <!-- ############HEADER TABLE############ --> <table width=100% height=100% border=1 bordercolor=#666666> <td valign=top class=table_head> <font color=#fefefe size=2> <div align=right> <?php // Connects to your Database mysql_connect("") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { echo '<font size=2 color=#ae854a>Welcome ' . $username . '</font> | <a href=myaccount.php>My Account</a> | <a href=logout.php>Logout</a>'; } } } else //if the cookie does not exist, they are taken to the login screen { echo '<font size=2 color=#fefefe><a href=register.php>Register</a> | <a href=login.php>Login</a> | Forgot Password'; } ?> </div> </font> </td> </tr> </table> <!-- ############MAIN TABLE############ --> <table width=100% height=100% border=1 bordercolor=#666666 bgcolor=#242424> <td valign=top> <!-- ############LOGO TABLE############ --> <table width=88% border=0 align=center> <tr> <td valign=top> <img src=./images/101_logo.png> <img src=./images/slogan.png> <img src=./images/cellhead.png align=right> </td> </tr> </table> <!-- ############NAVIGATION TABLE############ --> <table width=100% border=0> <td valign=top> <br> <font color=#fefefe size=5> <center> <a href=index.php><img src=images/homeout.png border=0></a> <a href=gallery.php><img src=images/galleryout.png border=0></a> <a href=tutorials.php><img src=images/tutorialsout.png border=0></a> <a href=artists.php><img src=images/artistsout.png border=0></a> <a href=contact.php><img src=images/contactout.png border=0></a> </center> </font> </td> </tr> </table> </td> </tr> </table> <center> and here is content holder.php <!-- ############CONTENT HOLDING TABLE############ --> <table width=100% height=100% border=0 bordercolor=#666666 class=table_content> <td valign=top> <br> <!-- ############CONTENT TABLE############ --> <table width=78% height=100% border=0 bordercolor=#666666 align=center> <tr> <td valign=top> <!-- ############LEFT TABLE############ --> <table border=1 width="14%" cellpadding="3" bordercolor=#fefefe cellspacing="3" align=left class=table_main> <th> <font color=#fefefe size=2> <center> Featured </center> </font> </th> <tr> <td valign=top> <center> <br> <img src=featured/cd1.jpg class=special> <br> <font color=#fefefe size=2>By Carl Dodds <br><br> <img src=featured/cd2.jpg class=special> <br> <font color=#fefefe size=2>By Carl Dodds <br><br> <img src=featured/cd3.jpg class=special> <br> <font color=#fefefe size=2>By Carl Dodds <br><br> <img src=featured/cd4.jpg class=special> <br> <font color=#fefefe size=2>By Carl Dodds <br><br> </td> </tr> </table> <!-- ############RIGHT TABLE############ --> <table border=1 width="14%" cellpadding="3" bordercolor=#fefefe cellspacing="3" align=right class=table_main> <th> <font color=#fefefe size=2> <center> Resources </center> </font> </th> <tr> <td valign=top> <center> <img src=images/blender.png> <br> <img src=images/blendercookie.png> <br><br> <img src=images/blendernation.jpg> <br><br> <img src=images/blenderunder.jpg> <br><br> <img src=images/rss.png> <img src=images/twit.png> <img src=images/fb.png> <img src=images/vim.png> </center> </td> </tr> </table> <!-- ############CENTER TABLE############ --> <table border=1 width="64%" cellpadding="3" cellspacing="3" bordercolor=#fefefe align=center class=table_main> <th> <center> <font color=#fefefe size=3> <center> <?php echo 'Today is ' . date("F j, Y, g:i a"); ?> </th> <tr> <td> <font color=#fefefe> Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960140 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 also i should note i use both these includes on everything else and they work fine, i also have a footer which i include onto the base, which basically just closes the tables from the content holder. I just dont understand why it ws working last night and isnt now. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960166 Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 In the header.php you have this code <?php // Connects to your Database mysql_connect("") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); Which really does not make anysense, as it is probably dieing everytime because you gave it nothing to connect to. That and you already have the connection information in the login script. Put it in one or the other not both and put it in correctly, that should solve your issue. EDIT: Another issue I just noticed is that you are calling header after output in the header.php. This will cause an error, any header calls need to be before any output. If at the top of your login script you added this code: error_reporting(E_ALL); ini_set("display_errors", 1); You will see the header errors. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960167 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 i thought that question may come up, i just removed the connection settings cos when i try to edit on this forum and i have to scroll the box down it keeps jumping back up to the top when i type, so i just deleted them. they do display he correct connection settings in the code though Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960168 Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 i thought that question may come up, i just removed the connection settings cos when i try to edit on this forum and i have to scroll the box down it keeps jumping back up to the top when i type, so i just deleted them. they do display he correct connection settings in the code though Here in lies the question, why do you need to open a connection twice? If it is to the same database/server one set of strings is fine and you will want to put them in the outter most file, if that makes sense (So keep the in the header.php). As far as your issue, it is header problems.... EDIT: Another issue I just noticed is that you are calling header after output in the header.php. This will cause an error, any header calls need to be before any output. If at the top of your login script you added this code: error_reporting(E_ALL); ini_set("display_errors", 1); You will see the header errors. Try that and see if you can fix the errors or post them here for help. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960172 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 okay i didnt fully understand you so here is the error code. you were right it is something to do with headers: Notice: Use of undefined constant ID_my_site - assumed 'ID_my_site' in /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/login.php on line 73 Warning: Cannot modify header information - headers already sent by (output started at /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/contentholder.php:83) in /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/login.php on line 73 Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960177 Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 In your header.php file, you have html output. This will cause issues when calling your header function on line 73 of login.php. To fix this you can do the bandaid apporach and use output buffering ob_start or fix your php so all the output is down at the end of the script and not while the script is executing. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960180 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 the Notice (1st error) is because you do not have quotes around ID_my_site or Key_my_site, so the parser thinks they are constants. and the header() issue is you trying to set a cookie after output has already been sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960184 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 i do have ' surrounding those things. Also what do i need o get rid of to correct the header? it looks for info within the cookie to see if the user is logged in then displays the corrent options, logout etc if not then it displays register etc Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960189 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 i do have ' surrounding those things. setcookie(ID_my_site, $_POST['username'], $hour)or die(mysql_error()); setcookie(Key_my_site, $_POST['pass'], $hour)or die(mysql_error()); there are no quotes around ID_my_site or Key_my_site .. i don't know where you're looking. and why the or die(mysql_error())? i noticed you have those all over your script. remove them all as they do nothing in the way you are using them. Also what do i need o get rid of to correct the header? it looks for info within the cookie to see if the user is logged in then displays the corrent options, logout etc if not then it displays register etc that kind of logic should be done at the top of your script(s). it does not need to be embedded in your script(s), ie: setting cookies, header() redirects, etc. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960192 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 okay there are now quotes around them, i was looking in the header file when you meant th elogin one. On the header file though i moved all of it to the top and the page doesnt display as it should now. This is what i moved to the top: <?php // Connects to your Database mysql_connect("sql304.000a.biz", "a000b_4450564", "984497") or die(mysql_error()); mysql_select_db("a000b_4450564_BBT") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die (mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { echo '<font size=2 color=#ae854a>Welcome ' . $username . '</font> | <a href=myaccount.php>My Account</a> | <a href=logout.php>Logout</a>'; } } } else //if the cookie does not exist, they are taken to the login screen { echo '<font size=2 color=#fefefe><a href=register.php>Register</a> | <a href=login.php>Login</a> | Forgot Password'; } ?> and my site is: http://blender101.000a.biz/ Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960206 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 how is it supposed to be displaying? need info. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960233 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 how is it supposed to be displaying? need info. this is how it should be: and this is how it is now http://blender101.000a.biz/ like i said i moved all of the stuff in header.php that related to the cookies to the top of the script and had everything else below. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960237 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 how about letting me know where to add this code so that it correctly displays the info when logged or not logged in. The echo bits i want in a table at the top which is already set up. <?php // Connects to your Database mysql_connect("sql304.000a.biz", "a000b_4450564", "984497") or die(mysql_error()); mysql_select_db("a000b_4450564_BBT") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die (mysql_error()); echo '<font size=2 color=#ae854a>Welcome ' . $username . '</font> | <a href=myaccount.php>My Account</a> | <a href=logout.php>Logout</a>'; } else //if the cookie does not exist, they are taken to the login screen { echo '<font size=2 color=#fefefe><a href=register.php>Register</a> | <a href=login.php>Login</a> | Forgot Password'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960307 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 if you put your code back to how it was before the display got messed up, and then do as premiso advised by adding ob_start() to the top of your scripts, and ob_end_flush() to the end: <?php ob_start(); //php stuff; ob_end_flush(); ?> only declare each once though, meaning, don't put ob_start(); at the top of every file and ob_end_flush(); at the bottom of every file. work with your sites hierarchy. alternatively, you can prepend and append files using either .htaccess or by editing your php.ini, where you can then create two files, the first being: begin_buffer.php <?php ob_start(); ?> and the second being: end_buffer.php <?php ob_end_flush(); ?> then, if you have access to your php.ini file, locate these two options and edit accordingly: auto_prepend_file = /path/to/begin_buffer.php auto_append_file = /path/to/end_buffer.php case 2 via .htaccess file: insert the following into a file and save it as .htaccess (save as "all files", not ".txt file); php_value auto_prepend_file begin_buffer.php php_value auto_append_file end_buffer.php that will have PHP automatically prepend and append files to your code. a simple way to ensure output buffering is used in it's simplest manner. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960314 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 okay i added them things before and after the php in header.php but i still get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/contentholder.php:83) in /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/login.php on line 73 Here is my code for header.php: <?php error_reporting(E_ALL); ini_set("display_errors", 1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb"> <head> <title>Blender 101 | Home</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-language" content="en-gb" /> <meta http-equiv="content-style-type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="resource-type" content="document" /> <meta name="distribution" content="global" /> <meta name="copyright" content="2000, 2002, 2005, 2007 phpBB Group" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" href="stylesheet.css" type="text/css" /> <link rel="stylesheet" href="css/gallery.css" type="text/css" media="screen" charset="utf-8" /> <script src="scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script> <script src="scripts/mootools-1.2-more.js" type="text/javascript"></script> <script src="scripts/jd.gallery.js" type="text/javascript"></script> <script src="scripts/jd.gallery.transitions.js" type="text/javascript"></script> <link rel="icon" type="image/gif" href="images/favicon.gif"> </head> <body> <!-- ############HEADER TABLE############ --> <table width=100% height=100% border=1 bordercolor=#666666> <td valign=top class=table_head> <font color=#fefefe size=2> <div align=right> <?php ob_start(); // Connects to your Database mysql_connect("sql304.000a.biz", "a000b_4450564", "984497") or die(mysql_error()); mysql_select_db("a000b_4450564_BBT") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die (mysql_error()); echo '<font size=2 color=#ae854a>Welcome ' . $username . '</font> | <a href=myaccount.php>My Account</a> | <a href=logout.php>Logout</a>'; } else //if the cookie does not exist, they are taken to the login screen { echo '<font size=2 color=#fefefe><a href=register.php>Register</a> | <a href=login.php>Login</a> | Forgot Password'; } ob_end_flush(); ?> </div> </font> </td> </tr> </table> <!-- ############MAIN TABLE############ --> <table width=100% height=100% border=1 bordercolor=#666666 bgcolor=#242424> <td valign=top> <!-- ############LOGO TABLE############ --> <table width=88% border=0 align=center> <tr> <td valign=top> <img src=./images/101_logo.png> <img src=./images/slogan.png> <img src=./images/cellhead.png align=right> </td> </tr> </table> <!-- ############NAVIGATION TABLE############ --> <table width=100% border=0> <td valign=top> <br> <font color=#fefefe size=5> <center> <a href=index.php><img src=images/homeout.png border=0></a> <a href=gallery.php><img src=images/galleryout.png border=0></a> <a href=tutorials.php><img src=images/tutorialsout.png border=0></a> <a href=artists.php><img src=images/artistsout.png border=0></a> <a href=contact.php><img src=images/contactout.png border=0></a> </center> </font> </td> </tr> </table> </td> </tr> </table> <center> Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960325 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 you started output buffering in header.php, but nowhere else .. notice the error you're still getting in login.php? k, let's build you an .htaccess file: open a blank file, and enter and the following two lines: php_value auto_prepend_file begin_buffer.php php_value auto_append_file end_buffer.php now, click "File > Save As > .htaccess", and make sure you do not save it as a text (.txt) file, but instead you select "All Files" from the "File Type" dropdown (or whatever it is). now, refer to my previous post and create the two files begin_buffer.php and end_buffer.php. upload all three (3) files to your root directory, and viola!, you have output buffering. let me know how that goes. Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960338 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 same error: Warning: Cannot modify header information - headers already sent by (output started at /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/contentholder.php:83) in /home/vol6/000a.biz/a000b_4450564/blender101.000a.biz/htdocs/login.php on line 73 followed your post down to the letter. Is there a way to check wether a user is logged in(which is all i want to do). I want it to check wether they are logged in or not in my heder.php from the code in login.php. Heres login.php again: <?php include('header.php'); include('contentholder.php'); // Connects to your Database mysql_connect("sql304.000a.biz", "a000b_4450564", "984497") or die(mysql_error()); mysql_select_db("a000b_4450564_BBT") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: index.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username'])or die(mysql_error()); $hour = time() + 3600; setcookie('ID_my_site', $_POST['username'], $hour)or die(mysql_error()); setcookie('Key_my_site', $_POST['pass'], $hour)or die(mysql_error()); //then redirect them to the members area header("Location: index.php")or die(mysql_error()); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } include('footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960343 Share on other sites More sharing options...
doddsey_65 Posted November 18, 2009 Author Share Posted November 18, 2009 okay ive done it, i added the ob_flush this to the top and bottom of login.php and it works fine now. Cheers for the advice everyone, im glad to be marking this as solved! Quote Link to comment https://forums.phpfreaks.com/topic/182026-solved-user-registration-not-working-anymore/#findComment-960361 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.