iarp Posted June 19, 2008 Share Posted June 19, 2008 Hey, I use this script on 3 different websites, all on the same host just different domains. This login.php page logins, sets the session variables and then forwards the user to the main page. For some reason, it's just stopped working on one of the sites and the user just sits on a blank page. It makes it to "exit(); // Quit the script." but for some reason won't forward the user as it does on the other sites. The only different between all the sites is the .htaccess RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteRule \.(css|jpe?g|gif|png)$ - [L] but that just adds www. in front of the url. login.php <?php $title = 'Login'; include('./includes/header.php'); if (isset($_POST['submitted'])) { // Check if the form has been submitted. require_once ('./includes/mysql.php'); // Connect to the database. // Validate the email address. if (!empty($_POST['username'])) { $un = escape_data($_POST['username']); } else { echo '<p><font color="red" size="+1">You forgot to enter your username!</font></p>'; $un = FALSE; } // Validate the password. if (!empty($_POST['pass'])) { $p = escape_data($_POST['pass']); } else { $p = TRUE; echo '<p><font color="red" size="+1">You forgot to enter your password!</font></p>'; } if ($un) { // If everything's OK. // Query the database. $query = "SELECT user_id, first_name, userlevel FROM " . TBL_USERS . " WHERE (username='$un') AND active IS NULL"; $result = mysql_query ($query); // or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_num_rows($result) == 1) { // A match was made. // Register the values & redirect. $row = mysql_fetch_array ($result, MYSQL_NUM); mysql_free_result($result); $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['userlevel'] = $row[2]; // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST']; // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p><font color="red" size="+1">Either the username and password entered do not match those on file or you have not yet activated your account.</font></p>'; } } else { // If everything wasn't OK. echo '<p><font color="red" size="+1">Please try again.</font></p>'; } } // End of SUBMIT conditional. ?> <h1>Login</h1> <form action="login.php" method="post" class="contact_login"> <p><label>Username:</label> <input type="text" name="username" size="20" maxlength="40" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?><?php if(isset($_GET['username'])) echo $_GET['username']; ?>" /></p> <p><label>Password:</label> <input type="password" name="pass" size="20" maxlength="20" value="<?php if(isset($_GET['temppassword'])) echo $_GET['temppassword']; ?>" /></p> <div align="center"> <input type="submit" name="submit" value="Login" /><br /> <small><a href="../forgot_password.php">Forgot Password</a> | <a href="../register.php">Register</a></small> </div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/110868-solved-header-not-forwarding/ Share on other sites More sharing options...
lilwing Posted June 19, 2008 Share Posted June 19, 2008 Try an output buffer with ob_start and ob_flush functions. I think the reason why It doesn't work is because you have output before the header. Oh, also, does the header really work the way you have it? I think you should try ("Location:" . $url); maybe that will make a difference. Quote Link to comment https://forums.phpfreaks.com/topic/110868-solved-header-not-forwarding/#findComment-568827 Share on other sites More sharing options...
iarp Posted June 19, 2008 Author Share Posted June 19, 2008 Yes it does work, i unno, i picked it up from a php book i read. BTW the ob_start and flush fixed the problem, it works as i need it now thanks. Quote Link to comment https://forums.phpfreaks.com/topic/110868-solved-header-not-forwarding/#findComment-568828 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.