Butler Posted April 24, 2011 Share Posted April 24, 2011 i am building a log in gate and am trying to figure out how i could make it so that when the user logs in it takes them to a url i have stored for them in the table Quote Link to comment https://forums.phpfreaks.com/topic/234554-log-in-help/ Share on other sites More sharing options...
Fadion Posted April 24, 2011 Share Posted April 24, 2011 <?php //successful login $url = $rows['url']; //url got from MySQL table header("Location: $url"); ?> To actually use header(), the script must have not send any output (html, js, css, php print, cookie, whatever) to the browser, or you'll get an error. To make for that problem, you can use output buffering or alternatively, meta refresh (deprecated) or javascript (not recommended). Quote Link to comment https://forums.phpfreaks.com/topic/234554-log-in-help/#findComment-1205414 Share on other sites More sharing options...
Butler Posted April 24, 2011 Author Share Posted April 24, 2011 <?php //successful login $url = $rows['url']; //url got from MySQL table header("Location: $url"); ?> To actually use header(), the script must have not send any output (html, js, css, php print, cookie, whatever) to the browser, or you'll get an error. To make for that problem, you can use output buffering or alternatively, meta refresh (deprecated) or javascript (not recommended). what does $rows = ??? Quote Link to comment https://forums.phpfreaks.com/topic/234554-log-in-help/#findComment-1205419 Share on other sites More sharing options...
Fadion Posted April 24, 2011 Share Posted April 24, 2011 I'll elaborate my answer. As you mentioned "URL stored in a table", I thought you had the basic idea. A simple login script <?php //username and password from POST data. Clean username for use in query and hash password. $username = mysql_real_escape_string($_POST['username']); $password = sha1($_POST['password']); //make a query to the 'users' table to see if a user with the correct username/password combination exists. $results = mysql_query("SELECT id, url FROM users WHERE username='$username' AND password='$password' LIMIT 1"); //if query returns 1 row, then the provided username/password are correct. if (mysql_num_rows($results)) { //fetch data into an associative array. $values = mysql_fetch_assoc($results); //create a session variable to hold the user's id. $_SESSION['user'] = $values['id']; //the url stored in the MySQL table. $url = $values['url']; //redirect the user to the url. header("Location: $url"); } ?> The script doesn't do any error handling, validation or whatever. It's just bare-bones to give you the idea. Quote Link to comment https://forums.phpfreaks.com/topic/234554-log-in-help/#findComment-1205422 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.