PHP - Header Problem
I've got this sign in code:
Code: [Select] [php] <?php include("conf.inc.php"); // Includes the db and form info. if ($_SESSION['logged'] == 1) { // User is already logged in. $_SESSION['email'] = $email; header("Location: main.php"); // Goes to main page. exit(); // Stops the rest of the script. } else { if (!isset($_POST['submit'])) { // If the form HAS NOT been submitted. echo "<td width=\"320\" height=\"50\" align=\"left\" valign=\"middle\"> </td>"; echo "<td width=\"360\" height=\"50\" align=\"left\" valign=\"middle\">"; echo "<form name=\"form\" action=\"index.php\" method=\"POST\" style=\"margin-bottom:0;\">"; echo "<a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a> "; echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onMouseOver=\"window.name = 'main'\" onClick=\"return popup(this, 'notes')\">Forgot Password</a><br>"; echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\"> "; echo "<input type=\"password\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000';}\"> "; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">"; echo "</form>"; } else { // If the form HAS been submitted $email = form($_POST['email']); $pword = md5($_POST['pword']); // Encrypts the password. $q = mysql_query("SELECT * FROM `signin` WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); // Checks to see if anything is in the db. if (!$r) { // There is nothing in the db. The username/password do not match up. echo "<td width=\"108\" height=\"50\" align=\"left\" valign=\"middle\"> </td>"; echo "<td width=\"572\" height=\"50\" align=\"left\" valign=\"middle\">"; echo "<form name=\"form\" action=\"index.php\" method=\"POST\" style=\"margin-bottom:0;\">"; echo " <a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a> "; echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onClick=\"return popup(this, 'notes')\">Forgot Password</a><br>"; echo "<font color=\"#FF0000\"><strong>Incorrect Email or Password.</strong></font> "; echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\"> "; echo "<input type=\"password\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000';}\"> "; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">"; echo "</form>"; } else { // If the username/password is invalid $_SESSION['logged'] = 1; // Sets the session. $_SESSION['email'] = $email; header("Location: main.php"); // THIS IS LINE 111 exit(); // Stops the rest of the script. } } } ?> [/php] And when I sign in with my user name and password, I get this warning message: Warning: Cannot modify header information - headers already sent by (output started at /home/content/29/6879529/html/calhoun/index.php:9) in /home/content/29/6879529/html/calhoun/head1.inc.php on line 111 Can anyone help me out and tell me what I need to do to correct this? Thanks in advance for your help! Similar TutorialsHi guys, I've got a header problem. I've read the header sticky post but i'm still not getting anywhere. I am currently working on a registration form which loops though checking the data entered meets certain criteria by calling various functions (min length, max length, preg match, etc...), if anything returns 'false' then the form is reproduced with the error message of why it failed and what needs to be changed. If everything returned is 'true' then all day matches what is expected and the code then runs an 'insert' command. If the insert is successful then the code should forward the user to a new page displaying 'registration complete'. However, the way I have written my code I am finding it near impossible to get the forward to be before anything is output to the browser therefore causing the header error. I have tried moving things around but i'm having no luck. The error I am getting is: Warning: Cannot modify header information - headers already sent by (output started at /websites/blahblahblah/register.php:6) in /websites/blahblahblah/register.php on line 77 The code there is relevant though as it is the code that make the connection to my DB. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php // *** Connection - START *** // connect to database $connect = @mysql_connect("test", "test", "test") or die(mysql_error()); if (!$connect) { do_error("Could not connect to the server"); } @mysql_select_db("test_db",$connect)or do_error("Could not connect to the database"); // *** Connection - END *** // This file includes all of the check functions for the code to run through include("check.php"); if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { $data= new check($_POST); $data->name('forename'); $data->name('surname'); if ( $data->pass == true ) { // Now we have the required data in the correct format do the code required to complete registration $forename=$data->input['forename']; $surname=$data->input['surname']; $query="INSERT INTO users ( forename, surname ) VALUES ('$forename' , '$surname' )"; if (mysql_query($query,$connect)) { //echo "success"; // once data is inserted, go to complete page header ("location: complete.php"); exit; } else { echo "Error: Please try again."; } } } else { $data= new check(); } ?> What am I actually doing wrong and how can i possibly get the insert script higher up the code?? Thanks the page below worked until i added the php include part to the top of the page and now i get the header error message for some of my web pages but i have fixed them all but this one. How do i fix this because i can't move them to the top of the page just under the php include like i needed to do with the other pages because if i move them up it will put the forms at the top aswell. <?php include("protect page file location"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Dvds</title> <link href="../../style.css" rel="stylesheet" type="text/css" /> </head> <link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="uploadify/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="uploadify/swfobject.js"></script> <script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#file_upload').uploadify({ 'uploader' : 'uploadify/uploadify.swf', 'script' : 'uploadify/uploadify.php', 'cancelImg' : 'uploadify/cancel.png', 'folder' : '../../dvds/dvd_files', 'displayData' : 'percentage', 'auto' : true, 'multi' : true }); }); </script> <body> <div class="container"> <div class="header"><br /><br /><br /> </div> <div class="sidebar1"> <ul class="nav"><b> <li><a href="../../">Home</a></li> <li><a href="../">Testimonials upload</a></li> <li><a href="../audio/">Audio Testimonials upload</a></li> <li><a href="../dvds/">Dvd's upload</a></li> <li><a href="../newsletter/">Newsletter upload</a></li> <li><a href="../news/">News box update</a></li> <li><a href="http://www.weblink.co.cc/admin/?logout=1">Logout</a></li> </b></ul></div> <div class="content"><div class="text"> <center><h3>Admin</h3> <br /> <p><input id="file_upload" name="file_upload" type="file" /></p></center> <center><p><form method="get" action="index.php"> <select name="id" class="inputstandard"> <option value="default">Select Dvd</option><?php include("dbinfo1.inc.php"); mysql_connect($localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query('SELECT * FROM Dvd ORDER BY id ASC') or die (mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo '<option value="' . $row['id'] . '" name="' . $row['id']. '">Dvd ' . $row['id']. '</option>'; } ?> </select> <input type="submit" value="Submit"> </form></p> <p><?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $file = $_GET["id"]; $result=mysql_query("SELECT * FROM Dvd where id='$file'") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); print '<form method="POST" action="insert_dvd.php">'; print '<table border="0">'; print '<tr>'; print '<td><input type="hidden" name="id" value="'.$file.'"></td>'; print '</tr>'; print '<tr>'; print '<td align="right">Dvd Name:</td>'; print '<td><input type="text" name="Watch" value="'.$row['Watch'].'" /></td>'; print '</tr>'; print '<td colspan="2" align="center"><input type="submit" name="submit" value="Update"></td>'; print '</tr>'; print '</table>'; print '</form>'; mysql_close($link); ?><br /><?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $file = $_GET["id"]; $result=mysql_query("SELECT * FROM Dvd where id='$file'") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); print '<form method="GET" action="delete.php">'; print '<table border="0">'; print '<tr>'; print '<td><input type="hidden" name="id" value="'.$file.'"></td>'; print '</tr>'; print '<tr>'; print '<td align="right">Dvd Name:</td>'; print '<td><input type="text" name="Watch" value="'.$row['Watch'].'.wmv" /></td>'; print '</tr>'; print '<td colspan="2" align="center"><input type="submit" name="submit" value="Delete"></td>'; print '</tr>'; print '</table>'; print '</form>'; mysql_close($link); ?> </p></center></div> </div> <div class="sidebar2"> <center><h4>Help</h4></center> <p>text here</p> </div> <div class="footer"> <center><p>&#169; Copyright 2010</p></center> </div> </div> </body> </html> the below are the php parts causing the problems. <?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $file = $_GET["id"]; $result=mysql_query("SELECT * FROM Dvd where id='$file'") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); print '<form method="POST" action="insert_dvd.php">'; print '<table border="0">'; print '<tr>'; print '<td><input type="hidden" name="id" value="'.$file.'"></td>'; print '</tr>'; print '<tr>'; print '<td align="right">Dvd Name:</td>'; print '<td><input type="text" name="Watch" value="'.$row['Watch'].'" /></td>'; print '</tr>'; print '<td colspan="2" align="center"><input type="submit" name="submit" value="Update"></td>'; print '</tr>'; print '</table>'; print '</form>'; mysql_close($link); ?> <br /> <?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $file = $_GET["id"]; $result=mysql_query("SELECT * FROM Dvd where id='$file'") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); print '<form method="GET" action="delete.php">'; print '<table border="0">'; print '<tr>'; print '<td><input type="hidden" name="id" value="'.$file.'"></td>'; print '</tr>'; print '<tr>'; print '<td align="right">Dvd Name:</td>'; print '<td><input type="text" name="Watch" value="'.$row['Watch'].'.wmv" /></td>'; print '</tr>'; print '<td colspan="2" align="center"><input type="submit" name="submit" value="Delete"></td>'; print '</tr>'; print '</table>'; print '</form>'; mysql_close($link); ?> Problem with this header. $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "From: $to\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion(); $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $body = "<html><body>".$table."</body></html>"; Can anyone tell me why? Hi! I'm not a very experienced PHPer. I keep getting this error... Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/2/6/j26183102/html/referral.php:11) in /home/content/j/2/6/j26183102/html/referral.php on line 295 Any suggestions? It works on one server but not my customers godaddy hosting site. Hello! My server hosting company has updated PHP from 4 to 5 version, and now the header function doesn't work very well anymore. It does load the new page everytime, like it should, but the data is not always refreshed. Not until I click "reload current page" from the browser. I'm using Firefox 3.6.3. Here's the code which worked just fine few days ago: Code: [Select] $url="thepage.php"; header("Location: ".$url); die(); I tried something like this, but that doesn't work either: Code: [Select] $url="thepage.php"; header("Refresh: 0; url=".$url); die(); This is really nasty problem... How can I fix it? My session start is in my session object and I include it at the top of my page prior my html code, yet I still get this warning: Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Users/Sites/writepaps/index.php:2) in /Users/Sites/writepaps/includes/functions/sessions.php on line 11 I include the object in index line 2. and line 11 is where my session start is in my construct function <?php require_once("database.php"); require_once("user.php"); class Sessions { public $logged_in = false; protected $username; protected $password; function __construct(){ session_start(); $this->check_login(); } .... Why is this happening? What im trying to do is have the webpage forward the user to another page after they fill out something for a certain element in the database. But the once I put the variable into a header for forwarding, the variable is thought to be a string instead of outputting its value it holds. Heres my code.... $variable = "nextPage"; header('Location:webpage.php?id=$variable'); But whats its doing is sending the user to the url "webpage.php?id=$variable" instead of "webpage.php?id=nextPage" What can I do to get the header to read the variable value and not the variable name? All help is greatly appreciated!!! Hi all, I am trying to send an image through header so I have two php files: test0.php Code: [Select] <html> <head> </head> <body> <?php $imagename='test.php'; ?> <img src="<?php echo $imagename; ?>"/> </body> </html> and test.php: Code: [Select] <html> <html> <head> </hesd> <body> <?php $image = imagecreatefromjpeg('images/1.jpg'); header('Content-Type: image/jpeg'); imagejpeg($image, '', 100); ?> </body> </html> but the image doesn't show . What is the correct way? Thank you in advance. Hello everyone, I'm just starting out with PHP as I need to create an online bookstore for a school project. I'm working by a magazine which should teach you exactly how to do this using PHP, but I've had a bunch of problems with the code they use and I don't really know what's going on. Anyway, this looks really simple and basically what it does is allows you to post a comment on a book, then returns you to the book's page. Problem is, I'm getting the Header may not contain more than a single header, new line detected. error and I can't figure out why. I've tried researching into the matter but all the cases I found had to do with returning to an url, which is not my case. Anyway, here's the snippet of code: The form: Code: [Select] <div style="width:400px; border:1px solid #ffffff; background-color:#F9F1E7; padding:5px"> <b>Adauga opinia ta:</b> <hr size="1"> <form action="adauga_comentariu.php" method="POST"> Nume: <input type="text" name="nume_utilizator"><br><br> Email: <input type="text" name="adresa_email"><br><br> Comentariu: <br> <textarea name="comentariu" cols="45"></textarea><br><br> <input type="hidden" name="id_carte" value="<?=id_carte?>"> <center><input type="submit" value="Adauga"</center> </form> </div> The script adaugare_comentariu.php: Code: [Select] <?php ob_start(); include("conectare.php"); $numeFaraTags=strip_tags($_POST['nume_utilizator']); $emailFaraTags=strip_tags($_POST['adresa_email']); $comentariuFaraTags=strip_tags($_POST['comentariu']); $sql="insert into comentarii (id_carte, nume_utilizator, adresa_email, comentariu) values(".$_POST['id_carte'].", '".$numeFaraTags."','".$emailFaraTags."','".$comentariuFaraTags."')"; mysql_query($sql); $inapoi="carte.php?id_carte=".$_POST['id_carte']; header("location:urldecode($inapoi)"); ob_end_flush(); ?> conectare.php connects to the mysql database. $inapoi is the variable which returns the user to carte.php (the book he posted a comment on), where id_carte is the book's unique id. I'm getting Header may not contain more than a single header, new line detected on line ten, which is the header line. Can anyone help me? I've been stumped on this for a few days now and I've just let it pass and started working on other bits, but it's bugging me too much and I'd like to fix it. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=350027.0 Can some one help please i always get this wrong dont now why keep saying header already been sent any help please and how to fix it Code: [Select] <?php session_start(); $conn = mysql_connect(""); $db = mysql_select_db("", $conn); if(isset($_POST['submit'])){ $user = mysql_escape_string($_POST['user']); $pass = mysql_escape_string($_POST['pass']); } if(empty($user) && empty($pass)){ exit; }else{ } ?> <?php $sql = mysql_query("SELECT * FROM useradmin WHERE dbusername= '".$user."' AND dbuserpass= '".$pass."'")or die(mysql_error()); $row = mysql_fetch_assoc($sql); $count = count($sql); $u = $row['dbusername']; $p = $row['dbuserpass']; if($u == $user && $p == $pass){ $_SESSION['access'] = "$u"; header("location: index.php"); }else { echo "Sorry there as been a problem!"; exit; } ?> Hi there, I have a form which displays a "successful" message if the form is completed correctly. However, I want the form to go to another url if it is successful. I have tried this, but I get the "headers already sent..." message // Add New Subscriber Success Message $successMsg = header('Location: http://www.example.com/'); is there another way to forward onto another page? Thanks How do I get this to put in the pilotID? Code: [Select] header("Location: logbook.php?id=" . $pilotid); Thanks! Hey guys, I have a problem, i'm using ob_start to send multiples headers and it works but the problem is that my metada is not being sent, when i remove the ob_start it gets sent. Is there a way i can allow more info to be sent with ob_start? or should i use other methods to redirect to pages? i dont want to use javascript or meta http because they are not very reliable is there any other way? Thanks for help. Hi is there a way that i can set header not go anywhere like the problem with this is that it still goes to the second header is there a way i can set if none do nothing exit? and else do the second header?? Code: [Select] <?php if ($_POST['agents']=="none") { header("location:#"); exit; // header("Location: {$_SERVER['PHP_SELF']}"); } else { header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php"); } ?> Hi everyone, I have a login area, and i also have set up for me is a view page... the view page is each user's sort of profile, it gets id and displays relevant content. i was wondering if i could get the id or post rather through a re-direct on log in? for example user logs in with username and password, user is re-directed to the view page like this: header( "refresh:5;url=view00=id.php " ); echo '<h1>You will be re-directed in 5 seconds...</h1>'; user is taken to view page where they can edit bit on it. So far though i'm getting page not found error? first of all is this possible? if not whats the correct way/better way? Thanks Does starting a Session send data to the Header? Debbie I have been trying to fix this for a really long time. It does not show an error on my local server but on my demo server it does.' What am I doing wrong? I have tried changing the location of the default.php file. I even tried require_once and require. Nothing worked. try logging in with random details with this link. You will see the error. http://goo.gl/3IetJ default.php <?php $hostname_default = "localhost"; $database_default = "mypass"; $username_default = "my_user"; $password_default = "my_pass"; $default = mysql_pconnect($hostname_default, $username_default, $password_default) or trigger_error(mysql_error(),E_USER_ERROR); ?> login.php <?php if (!isset($_SESSION)) { session_start(); } if (!empty($_REQUEST['password'])) { include("../Connections/default.php"); $username = $_REQUEST['username']; $password = md5(md5($_REQUEST['password'])+salt); mysql_select_db($database_default, $default); $login_check = "SELECT * FROM users WHERE username = '$username' AND password = '$password'"; $login = mysql_query($login_check, $default) or die(mysql_error()); $row_login = mysql_fetch_assoc($login); $val_login = mysql_num_rows($login); if ($val_login == '1') { $_SESSION['E_User'] = $row_login['username']; header('Location: index.php'); } else { header('Location: login.php?error=1&username='.$username.''); } } ?> I want to set the correct header / cache values for a site. I am working on a social network / forum style site. I want to ensure that every page a user requests results in a fresh one being requested from the server as most content changes by the minute. (1) How would I set this? (2) Also, can I prevent nav bars being reloaded as these never, ever change. |