MesaFloyd Posted April 9, 2008 Share Posted April 9, 2008 Hello, I have a php login script I found on evolt. For the most part works very well. I have made several successful mods, but I have a problem I just cannot solve, been working on this one issue for 2-3 weeks, Im not a real programmer so please be gentle The script is for registering users, not unlike this forum. The register pages has 6 fields. Three are empty for the user to fill out(name-password-email), the other 3 are autofilled(IP-chkbox-timedate). When the user fills the 3fields then hits the Join! button the 6 fields all properly register to the mysql database, but, after it is registered the screen to the user does not indicate to the user that he is now registered...i.e. "Registered! Thank you..." the program just seems to jump over that part.. the screen puts up the original 'Register' screen again with the 3 fields emptied. IB stumpted .... any help would be very much appreciated. I have asked several 'experts' but with no solution... this is still killing me... Here is the section of the code I think it is in. Thanks in advance for any help. I could put up the whole file is needed(actually not that big) ////////This is where my problem is <I think> ... ////////When I press Join! button, the routine adds the new user to db OK but /////// instead of going to the "Registered! Thank you.." below it empties the 3 fields(user,pass,email) and starts again /////// asking you to register<again>. The user gets no indication that he was registered. /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus() { $uname = $_SESSION['reguname']; if ($_SESSION['regresult']) { ?> <h1>Registered!</h1> <p>Thank you.. <br> Your information has been added to the database, you may now <a href="index.php" title="Login">log in</a></p> <?php } else { ?> <h1>Registration Failed</h1> <p>We're sorry, but an error has occurred and your registration for the username <b><?php echo $uname; ?></b>, could not be completed.<br> Please try again at a later time.</p> <?php } $_SESSION['reguname'] = NULL; $_SESSION['registered'] = NULL; $_SESSION['regresult'] = NULL; } if (isset($_SESSION['registered'])) { /** * This is the page that will be displayed after the * registration has been attempted. */ ?> <html> <title>Registration Page</title> <body> <?php displayStatus(); ?> </body> </html> <?php return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ if (isset($_POST['subjoin'])) { /* Make sure all fields were entered */ if (!$_POST['user'] || !$_POST['pass']) { die('You didn't fill in a required field.'); } /* FKadded this -- checks that email field has characters */ if (!$_POST['email']) { die('You didn't fill in the email field, silly'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if (strlen($_POST['user']) > 30) { die("Sorry, the username is longer than 30 characters, please shorten it."); } /* Check if username is already in use */ if (usernameTaken($_POST['user'])) { $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } /* Add the new account to the database */ $password = ($_POST['pass']);//FK removed md5.. was... $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $password, $pcidip, $datetime, $email, $emailchk);//FK-added $pcidip...$emailchk $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[php_SELF]\">"; return; } else { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr> <tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br /> <!-- FKinsert begins here --> <tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?>" size="20"></td></tr><br /> <tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value=" <?php echo date("Y.m.d - h:i:s"); ?>" size="20"></td></tr><br> <!-- FK insert ends here --> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> <?php } ?> I have marked with /////// where I think the problem is, but any help would be greatly appreciated... pls remember I am not a 'real' programmer, but I try very hard.. Floyd Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/ Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 quick glance through - lots of text and code. anyway, the thank you will only appear as long as $_SESSION['regresult'] exists or is true etc. so where it INSERT's the new user info, add $_SESSION['regresult'] = true; under the query. Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513479 Share on other sites More sharing options...
MesaFloyd Posted April 10, 2008 Author Share Posted April 10, 2008 uniflair, thanks so much... I know it is not very well written but it does function for the most part, here is the entire file...(not really much bigger).... sure hope you can help...I've been spending soo much time, and Im just not a programmer... just enought to be dangerous. <?php session_start(); include ("database.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ function usernameTaken($username) { global $conn; if (!get_magic_quotes_gpc()) { $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q, $conn); $num = mysql_numrows($result); return $num; } /** * Inserts the given (username, password) pair * into the database. Returns true on success, * false otherwise. */ function addNewUser($username, $password, $pcidip, $datetime, $email, $emailchk) { global $conn; $q = "INSERT INTO users VALUES ('$username', '$password', '$pcidip', '$datetime', '$email', '$emailchk')"; $query = mysql_query($q, $conn); return $query; } ////////This is where my problem is <I think> ... ////////When I press Join! button, the routine adds the new user to db OK but /////// instead of going to the "Registered! Thank you.." below it empties the 3 fields(user,pass,email) and starts again /////// asking you to register<again>. The user gets no indication that he was registered. /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus() { $uname = $_SESSION['reguname']; if ($_SESSION['regresult']) { ?> <h1>Registered!</h1> <p>Thank you.. <br> Your information has been added to the database, you may now <a href="index.php" title="Login">log in</a></p> <?php } else { ?> <h1>Registration Failed</h1> <p>We're sorry, but an error has occurred and your registration for the username <b><?php echo $uname; ?></b>, could not be completed.<br> Please try again at a later time.</p> <?php } $_SESSION['reguname'] = NULL; $_SESSION['registered'] = NULL; $_SESSION['regresult'] = NULL; } if (isset($_SESSION['registered'])) { /** * This is the page that will be displayed after the * registration has been attempted. */ ?> <html> <title>Registration Page</title> <body> <?php displayStatus(); ?> </body> </html> <?php return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ if (isset($_POST['subjoin'])) { /* Make sure all fields were entered */ if (!$_POST['user'] || !$_POST['pass']) { die('You didn't fill in a required field.'); } /* FKadded this -- checks that email field has characters */ if (!$_POST['email']) { die('You didn't fill in the email field, silly'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if (strlen($_POST['user']) > 30) { die("Sorry, the username is longer than 30 characters, please shorten it."); } /* Check if username is already in use */ if (usernameTaken($_POST['user'])) { $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } /* Add the new account to the database */ $password = ($_POST['pass']);//FK removed md5.. was... $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $password, $pcidip, $datetime, $email, $emailchk);//FK-added $pcidip...$emailchk $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[php_SELF]\">"; return; } else { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr> <tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br /> <!-- FKinsert begins here --> <tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?>" size="20"></td></tr><br /> <tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value=" <?php echo date("Y.m.d - h:i:s"); ?>" size="20"></td></tr><br> <!-- FK insert ends here --> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> <?php } ?> This code does work except for this one issue... Floyd ??? Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513486 Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 couple of syntax errors, so i'm suprised it got that far anyway - <?php session_start(); include ("database.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ function usernameTaken($username) { global $conn; if (!get_magic_quotes_gpc()) { $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q, $conn); $num = mysql_numrows($result); return $num; } /** * Inserts the given (username, password) pair * into the database. Returns true on success, * false otherwise. */ function addNewUser($username, $password, $pcidip, $datetime, $email, $emailchk) { global $conn; $q = "INSERT INTO users VALUES ('$username', '$password', '$pcidip', '$datetime', '$email', '$emailchk')"; $query = mysql_query($q, $conn); return $query; } ////////This is where my problem is <I think> ... ////////When I press Join! button, the routine adds the new user to db OK but /////// instead of going to the "Registered! Thank you.." below it empties the 3 fields(user,pass,email) and starts again /////// asking you to register<again>. The user gets no indication that he was registered. /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus() { // do not need to define $uname if ($_SESSION['regresult']) { ?> <h1>Registered!</h1> <p>Thank you.. <br> Your information has been added to the database, you may now <a href="index.php" title="Login">log in</a></p> <?php } else { ?> <h1>Registration Failed</h1> <p>We're sorry, but an error has occurred and your registration for the username <b><?php echo $_SESSION['reguname']; ?></b>, could not be completed.<br> Please try again at a later time.</p> <?php } $_SESSION['reguname'] = NULL; $_SESSION['registered'] = NULL; $_SESSION['regresult'] = NULL; } if (isset($_SESSION['registered'])) { /** * This is the page that will be displayed after the * registration has been attempted. */ ?> <html> <title>Registration Page</title> <body> <?php displayStatus(); ?> </body> </html> <?php return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ // changed to elseif - just cosmetic elseif (isset($_POST['subjoin'])) { /* Make sure all fields were entered */ if (!$_POST['user'] || !$_POST['pass']) { die('You didn\'t fill in a required field.'); } /* FKadded this -- checks that email field has characters */ if (!$_POST['email']) { die('You didn\'t fill in the email field, silly'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if (strlen($_POST['user']) > 30) { die("Sorry, the username is longer than 30 characters, please shorten it."); } /* Check if username is already in use */ if (usernameTaken($_POST['user'])) { $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } /* Add the new account to the database */ $password = ($_POST['pass']);//FK removed md5.. was... $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $password, $pcidip, $datetime, $email, $emailchk);//FK-added $pcidip...$emailchk $_SESSION['registered'] = true; // Check if session.use_cookies is set. if not then add the session id to the query string. $query = (ini_get("session.use_cookies") == 1)? "" : "?".ini_get("session.name")."=".SID; // Redirect using headers to this page. Header("Location: ".$_SERVER['PHP_SELF'].$query); exit(); } else { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr> <tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br /> <!-- FKinsert begins here --> <tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?>" size="20"></td></tr><br /> <tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value=" <?php echo date("Y.m.d - h:i:s"); ?>" size="20"></td></tr><br> <!-- FK insert ends here --> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> <?php } ?> i made a few changes like using Header() to redirect instead of echoing meta tags. Fixed the two syntax errors, i added a check to see if your server setup uses session cookies to store the session id, if it doesn't it will redirect to the page with a session id query string. hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513538 Share on other sites More sharing options...
MesaFloyd Posted April 10, 2008 Author Share Posted April 10, 2008 replaced the entire file with your changes.... same.. same... just does not go to the "Registered! Thank you...." Thanks for trying.... could it be something on the server side? my providor is runnin php 4.4.7 (Keep me away from sharp objects)... thank for trying.. any other thoughts. Floyd Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513563 Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 ok try print_r($_SESSION); after session_start(); give us the output source (HTML). --- also i made a booboo lol, instead of $query = (ini_get("session.use_cookies") == 1)? "" : "?".ini_get("session.name")."=".SID; use $query = (ini_get("session.use_cookies") == 1)? "" : "?".SID; hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513567 Share on other sites More sharing options...
MesaFloyd Posted April 10, 2008 Author Share Posted April 10, 2008 sorry not following you..... Not sure what to do with ok try print_r($_SESSION); after session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513571 Share on other sites More sharing options...
MesaFloyd Posted April 10, 2008 Author Share Posted April 10, 2008 here's the HTML with the $query change <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="/register.php" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr> <tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br /> <!-- FKinsert begins here --> <tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value=" 70.191.87.243" size="20"></td></tr><br /> <tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value=" 2008.04.09 - 11:50:44" size="20"></td></tr><br> <!-- FK insert ends here --> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513575 Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 try reading a basic book on php, books are really helpful and explain some of the useful php functions, such as print_r the query change will only be nopticable after you submit the form... the top of the php scripts has a call to session_start(); <?php session_start(); include ("database.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ so put print_r($_SESSION); underneath it: <?php session_start(); print_r($_SESSION); include ("database.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ then try submitting the form again and give me the output source (HTML) of that hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513619 Share on other sites More sharing options...
MesaFloyd Posted April 10, 2008 Author Share Posted April 10, 2008 I added the print_r as you said, like this... session_start(); print_r($_SESSION); include ("database.php"); Now, the Join! button brings up a screen with only 'Array()' on screen Here is the HTML for that screen Array ( ) For that it is worth, the new user that "Joined" did get registered in the DB... (BTW I do have a couple of basic books that I am using but I have no formal teaching, and no one to talk with about allot of rudimentary stuff, so I struggle. Im 62, my kids are gone, my piers have no idea bout this stuff and I live alone with 'Sludge'(cat), ... These forums are my only contact with technically astute people. I do not use these forum's until I am totally stuck... I really appreciate your help... thanks for your patience-really) This particular problem is difficult to weed out of the books I have... Floyd Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-513801 Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 I see, this is a very strange problem, your session info is not getting passed to the next page. try this: (ive added a few more debug lines, tell us what the HTML source is for each page <?php session_start(); include ("database.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ function usernameTaken($username) { global $conn; if (!get_magic_quotes_gpc()) { $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q, $conn); $num = mysql_numrows($result); return $num; } /** * Inserts the given (username, password) pair * into the database. Returns true on success, * false otherwise. */ function addNewUser($username, $password, $pcidip, $datetime, $email, $emailchk) { global $conn; $q = "INSERT INTO users VALUES ('$username', '$password', '$pcidip', '$datetime', '$email', '$emailchk')"; $query = mysql_query($q, $conn); return $query; } ////////This is where my problem is <I think> ... ////////When I press Join! button, the routine adds the new user to db OK but /////// instead of going to the "Registered! Thank you.." below it empties the 3 fields(user,pass,email) and starts again /////// asking you to register<again>. The user gets no indication that he was registered. /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus() { // do not need to define $uname if ($_SESSION['regresult']) { ?> <h1>Registered!</h1> <p>Thank you.. <br> Your information has been added to the database, you may now <a href="index.php" title="Login">log in</a></p> <?php } else { ?> <h1>Registration Failed</h1> <p>We're sorry, but an error has occurred and your registration for the username <b><?php echo $_SESSION['reguname']; ?></b>, could not be completed.<br> Please try again at a later time.</p> <?php } $_SESSION['reguname'] = NULL; $_SESSION['registered'] = NULL; $_SESSION['regresult'] = NULL; } // END OF FUNCTIONS if (isset($_SESSION['registered'])) { // Debug Line print_r($_SESSION); echo(" ^ SESSION_ID = ".SID." - ".session_id()); /** * This is the page that will be displayed after the * registration has been attempted. */ ?> <html> <title>Registration Page</title> <body> <?php displayStatus(); ?> </body> </html> <?php return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ // changed to elseif - just cosmetic elseif (isset($_POST['subjoin'])) { /* Make sure all fields were entered */ if (!$_POST['user'] || !$_POST['pass']) { die('You didn\'t fill in a required field.'); } /* FKadded this -- checks that email field has characters */ if (!$_POST['email']) { die('You didn\'t fill in the email field, silly'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if (strlen($_POST['user']) > 30) { die("Sorry, the username is longer than 30 characters, please shorten it."); } /* Check if username is already in use */ if (usernameTaken($_POST['user'])) { $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } /* Add the new account to the database */ $password = ($_POST['pass']);//FK removed md5.. was... $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $password, $pcidip, $datetime, $email, $emailchk);//FK-added $pcidip...$emailchk $_SESSION['registered'] = true; // Check if session.use_cookies is set. if not then add the session id to the query string. $query = (ini_get("session.use_cookies") == 1)? "" : "?".ini_get("session.name")."=".session_id(); // Debug Line print_r($_SESSION); echo(" ^ SESSION_ID = ".SID." - ".session_id()); // Redirect using headers to this page. Header("Location: ".$_SERVER['PHP_SELF'].$query); exit(); } else { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr> <tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br /> <!-- FKinsert begins here --> <tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?>" size="20"></td></tr><br /> <tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value=" <?php echo date("Y.m.d - h:i:s"); ?>" size="20"></td></tr><br> <!-- FK insert ends here --> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514332 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2008 Author Share Posted April 11, 2008 Installed the code as you posted. registered as uniflare02, and pressed Join! and got a page with this --- Array ( [reguname] => uniflare02 [regresult] => 1 [registered] => 1 ) ^ SESSION_ID = - 27cb5544cd0fbfda84c74b0260939bab --- Here is the HTML of that Array ( [reguname] => uniflare02 [regresult] => 1 [registered] => 1 ) ^ SESSION_ID = - 27cb5544cd0fbfda84c74b0260939bab also, uniflare02 did get registered in the database. Floyd Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514349 Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 ohh ok SID CONSTANT doesnt seem to exist in your php version. ok go into php.ini and check to make sure session.use_cookies is 0 or 1. this may work anyway: <?php session_start(); include ("database.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ function usernameTaken($username) { global $conn; if (!get_magic_quotes_gpc()) { $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q, $conn); $num = mysql_numrows($result); return $num; } /** * Inserts the given (username, password) pair * into the database. Returns true on success, * false otherwise. */ function addNewUser($username, $password, $pcidip, $datetime, $email, $emailchk) { global $conn; $q = "INSERT INTO users VALUES ('$username', '$password', '$pcidip', '$datetime', '$email', '$emailchk')"; $query = mysql_query($q, $conn); return $query; } ////////This is where my problem is <I think> ... ////////When I press Join! button, the routine adds the new user to db OK but /////// instead of going to the "Registered! Thank you.." below it empties the 3 fields(user,pass,email) and starts again /////// asking you to register<again>. The user gets no indication that he was registered. /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus() { // do not need to define $uname if ($_SESSION['regresult']) { ?> <h1>Registered!</h1> <p>Thank you.. <br> Your information has been added to the database, you may now <a href="index.php" title="Login">log in</a></p> <?php } else { ?> <h1>Registration Failed</h1> <p>We're sorry, but an error has occurred and your registration for the username <b><?php echo $_SESSION['reguname']; ?></b>, could not be completed.<br> Please try again at a later time.</p> <?php } $_SESSION['reguname'] = NULL; $_SESSION['registered'] = NULL; $_SESSION['regresult'] = NULL; } // END OF FUNCTIONS if (isset($_SESSION['registered'])) { /** * This is the page that will be displayed after the * registration has been attempted. */ ?> <html> <title>Registration Page</title> <body> <?php displayStatus(); ?> </body> </html> <?php return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ // changed to elseif - just cosmetic elseif (isset($_POST['subjoin'])) { /* Make sure all fields were entered */ if (!$_POST['user'] || !$_POST['pass']) { die('You didn\'t fill in a required field.'); } /* FKadded this -- checks that email field has characters */ if (!$_POST['email']) { die('You didn\'t fill in the email field, silly'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if (strlen($_POST['user']) > 30) { die("Sorry, the username is longer than 30 characters, please shorten it."); } /* Check if username is already in use */ if (usernameTaken($_POST['user'])) { $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } /* Add the new account to the database */ $password = ($_POST['pass']);//FK removed md5.. was... $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $password, $pcidip, $datetime, $email, $emailchk);//FK-added $pcidip...$emailchk $_SESSION['registered'] = true; // Check if session.use_cookies is set. if not then add the session id to the query string. $query = (ini_get("session.use_cookies") == 1)? "" : "?".ini_get("session.name")."=".session_id(); // Redirect using headers to this page. Header("Location: ".$_SERVER['PHP_SELF'].$query); exit(); } else { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr> <tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br /> <!-- FKinsert begins here --> <tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?>" size="20"></td></tr><br /> <tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value=" <?php echo date("Y.m.d - h:i:s"); ?>" size="20"></td></tr><br> <!-- FK insert ends here --> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> <?php } ?> I believe the problem is your not using session cookies, so you will have to either make a cookie yourself and use session_id() to set the session id, or pass the session id in the URL like i have done for you with the redirect. hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514353 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2008 Author Share Posted April 11, 2008 Ok now my ignorance will really start to show first, I tried your last post.... still works exactly as before... just does not give the indication the user got register... identical. also, the user did get registered in the db now for my ignorance... Ignorance #1 I do not have a php.ini file, and I do not know where to put it or how to make it Ignorance #2 I do have session cookies and they works fine... there are 4 files in this register.php.... the one your working on index.php login.php logout.php am I killing you yet? Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514365 Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 Ok im completely out of ideas without messing with it my self. ill pm you my details maybe we can sort this out. Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514393 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2008 Author Share Posted April 11, 2008 uniflare, I truly appreciate all you've done.... I don't want to take any more of your time. I was really hoping it would be obvious to a trained eye, but I guess I augured myself into a pretty good hole. You have done so much for am already. unless you get an "epiphany" ...please don't beat yourself any further with this.... Thanks for your time amigo. Floyd Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514403 Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 Floyd no worries m8, if i start helping someone i make it a point to see them through - check your PM inbox for my email address and add me to msn/yahoo or whatever. Alternatively you can email me your db dump file from phpmyadmin (database.sql) and zip up your script files. I'll take a look and post my findings on here for all to see. It probably is obvious when you find it, but it's the old "Needle in a haystack" thing . Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514718 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2008 Author Share Posted April 11, 2008 Odd, I sent you an email yesterday to that address, and apparently you did not receive it. I just sent you another, please ping to to ensure we have an email communication and then I will send the files Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-514730 Share on other sites More sharing options...
uniflare Posted April 12, 2008 Share Posted April 12, 2008 strange lol, only just got em , lets see if we can sort this out Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-515354 Share on other sites More sharing options...
MesaFloyd Posted April 12, 2008 Author Share Posted April 12, 2008 Please check your email, if you do not have a message from me, please let me know via this forum thanks again my friend Quote Link to comment https://forums.phpfreaks.com/topic/100386-join-button-does-not-jump-to-correct-locationpage/#findComment-515486 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.