1984321 Posted July 1, 2010 Share Posted July 1, 2010 Hi readers, recently I have decided to upload my php/mysql website online and found an error that I can't resolve. Basically when I login/logout as an user it won't redirect me to the right web page instead it returns a blank page with the same URL , this problem only occur online but works fine in the localhost server. The login page is used to prevent unauthorised user from using the private webpage and not for customizing unique page for each user. The redirect_to function is in function.php Redirect_to function: function redirect_to( $location = NULL ) { if ($location != NULL) { header("Location: {$location}"); exit; } Logout.php: <?php require_once("includes/function.php"); ?> <?php session_start(); $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); redirect_to("login.php?logout=1"); ?> Login.php: <?php if(logged_in()) { redirect_to("staff.php"); } include_once("includes/form_functions.php"); if (isset($_POST['submit'])) { $errors = array(); $required_fields = array('username', 'password'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $fields_with_lengths = array('username' => 15, 'password' => 20); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); if (empty ($errors) ) { $query = "SELECT user_id, username "; $query .= "FROM users "; $query .= "WHERE username = '{$username}'"; $query .= "AND hashed_password = '{$hashed_password}'"; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if(mysql_num_rows($result_set) == 1) { $found_user = mysql_fetch_array($result_set); $_SESSION['user_id'] = $found_user['user_id']; $_SESSION['username'] = $found_user['username']; redirect_to("staff.php"); } else { $message = "Username/password combination incorrect.<br /> Please make sure your caps lock key is off and try again."; } } else { if(count($errors) ==1){ $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } } else { if (isset($_GET['logout']) && $_GET['logout'] ==1) { $message = "You are now logged out."; } $username = ""; $password = ""; I thank you in advance for reading this post, any help that can reslove this problem is very much appreciated. Many Thanks! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 1, 2010 Share Posted July 1, 2010 It may sometimes work with a relative one, but the Location header requires an absolute URL. Quote Link to comment Share on other sites More sharing options...
1984321 Posted July 1, 2010 Author Share Posted July 1, 2010 i did try changing the relative URL to absolute ones, still dosen't work same problem occurs with a nice clean blank page. Quote Link to comment Share on other sites More sharing options...
1984321 Posted July 2, 2010 Author Share Posted July 2, 2010 bump Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 2, 2010 Share Posted July 2, 2010 You may have a space or something else that is outputting which would make the header fail. Try adding this up top: error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 2, 2010 Share Posted July 2, 2010 You can't have any output, spaces HTML anything before a header() call. You do here: <?php require_once("includes/function.php"); ?> these two blank lines are interpretted as HTML whitespace and sent to the browser, because they aren't in php tags <?php session_start(); Should be: <?php require_once("includes/function.php"); session_start(); Your other server must have had output buffering turned on in php.ini that buffered the output before the header. Quote Link to comment Share on other sites More sharing options...
1984321 Posted July 2, 2010 Author Share Posted July 2, 2010 nice one dude, is all working m8. thanks ! Quote Link to comment 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.