metalhead41 Posted February 23, 2008 Share Posted February 23, 2008 Quick one this time... On my test server running php 5.2.5 the function header('Location: main.php'); moves the user to the user area after they have logged in. On a live server runnign php 4.4.8 it's not working, instead I have to reclick on the staff are link which then moves me to the correct area. Any help would be appreciated ??? Link to comment https://forums.phpfreaks.com/topic/92591-header-function-doesnt-appear-to-be-working/ Share on other sites More sharing options...
kenrbnsn Posted February 23, 2008 Share Posted February 23, 2008 Please post the relevant code between tags. Ken Link to comment https://forums.phpfreaks.com/topic/92591-header-function-doesnt-appear-to-be-working/#findComment-474487 Share on other sites More sharing options...
metalhead41 Posted February 23, 2008 Author Share Posted February 23, 2008 On another test server that is running php 5.2.2 it does the same thing. Looking at the logfiles I get this when logging in: [23-Feb-2008 14:55:34] PHP Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Websites\Erith\stafflogin.php:7) in C:\wamp\www\Websites\Erith\includes\login.php on line 24 This is the login.php script <?php $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { include 'library/config.php'; include 'library/opendb.php'; $userId = $_POST['txtUserId']; $password = $_POST['txtPassword']; // check if the user id and password combination exist in database $sql = "SELECT user_name,account_type FROM users WHERE user_name = '$userId' AND user_password = md5('$password')"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); // the user id and password match, // set the session $_SESSION['username'] = $_POST['txtUserId']; $_SESSION['account_type'] = $row['account_type']; $_SESSION['db_is_logged_in'] = true; // after login we move to the main page header('Location: main.php'); exit; } else { $errorMessage = 'Sorry, wrong user id / password'; } include 'library/closedb.php'; } ?> <?php if ($errorMessage != '') { ?> <p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p> <?php } ?> <div id="login"> <form action="" method="post" name="frmLogin" id="frmLogin"> <label>User Name:</label> <input name="txtUserId" type="text" id="txtUserId" /> <label>Password:</label> <input name="txtPassword" type="password" id="txtPassword" /> <label> </label> <input name="btnLogin" type="submit" id="btnLogin" value="Login" /> </form> </div> This is main.php <?php // like i said, we must never forget to start the session session_start(); include 'library/config.php'; include 'library/opendb.php'; // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page header('Location: stafflogin.php'); include 'library/closedb.php'; exit; } $admin = "1"; $user = "2"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Erith Secondary School :: A Foundation School and a Specialist School in Sports Mathematics & Computing</title> <style type="text/css" media="all"> @import "./scripts/main.css"; </style> <script type="text/javascript"> function delArticle(id, name) { if (confirm("Are you sure you want to delete '" + name + "'")) { window.location.href = 'main.php?del=' + id; } } </script> </head> <body> <div id="sitewrap"> <?php include'includes/header.php';?> <?php include'includes/menu.php';?> <div id="contents"> <?php include'includes/date.php'?> <p>Welcome <?php echo $_SESSION['username'];?> how are you today?</p> <p><a href="./includes/logout.php">Click here to Logout</a></p> <div id="download"> <?php if($_SESSION['account_type'] == $admin){ echo "You can use this to upload and download new memo's or bulletins.";?><br /> <?php echo "Please only upload word files or PDF's. Make sure your files are labled appropriatley."; include 'includes/admin.php'; } if($_SESSION['account_type'] == $user){ echo "<p>Use these links to download the latest bulletin and memo.</p>"; include 'includes/user.php'; } ?> </div> <p><a href="./includes/logout.php">Click here to Logout</a></p> </div> <?php include'includes/footer.php';?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/92591-header-function-doesnt-appear-to-be-working/#findComment-474500 Share on other sites More sharing options...
metalhead41 Posted February 23, 2008 Author Share Posted February 23, 2008 Nevermind, sorted it out... I didn't see the sticky about headers at the top Link to comment https://forums.phpfreaks.com/topic/92591-header-function-doesnt-appear-to-be-working/#findComment-474534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.