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! Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/ 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. Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/#findComment-1079920 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. Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/#findComment-1079972 Share on other sites More sharing options...
1984321 Posted July 2, 2010 Author Share Posted July 2, 2010 bump Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/#findComment-1080156 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'); Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/#findComment-1080322 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. Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/#findComment-1080428 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 ! Link to comment https://forums.phpfreaks.com/topic/206443-redirct_to-function-help/#findComment-1080430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.