PHP - Headers Not Working
I keep getting the following error and its frustrating the hell out of me, supposedly to do with whitespace but i see no problems in my code.
Error: Warning: Cannot modify header information - headers already sent by (output started at /home/robwdri1/public_html/bsddesigns.co.uk/eventline/carddetails.php:18) in /home/robwdri1/public_html/bsddesigns.co.uk/eventline/carddetails.php on line 120 Code: Code: [Select] <?php // Date from form put into variables $cardnumber = $_POST['cardnumber']; $holdersname = $_POST['holdersname']; $expirydate = $_POST['expirydate']; // Card Check Function function LuhnCheck($cardnumber) { $sum = 0; $alt = false; for($i = strlen($cardnumber) - 1; $i >= 0; $i--) { if($alt) { $temp = $cardnumber[$i]; $temp *= 2; $cardnumber[$i] = ($temp > 9) ? $temp = $temp - 9 : $temp; } $sum += $cardnumber[$i]; $alt = !$alt; } return $sum % 10 == 0; } // Check if works if (!empty($cardnumber)) { if (LuhnCheck($cardnumber)) { header("location: confirmation.php"); } else { echo '<font color="red">Error, wrong card details!</font>'; } } ?> Any help please. Similar Tutorialsplease help, here is all my code: <div id='div_phone_big'> </div> <head> <script type="text/JavaScript"> function getChoice(val) { yesNo = new Array("Yes", "No"); var getsel = document.contactus.yesnolist.value; var e = document.getElementById("yesnolist"); var strUser = e.options[e.selectedIndex].value; if (strUser == "no") { //alert('lakjdlakjsdlajd'); window.location.href = "http://www.rainbowcode.net/index.php/util/faq"; //document.write(window.location.href); window.location('http://www.rainbowcode.net/index.php/util/faq'); } else { document.contactus.emailreply.value = ""; document.contactus.commtext.value = ""; document.contactus.message.value = ""; document.contactus.commlist.value = ""; } return strUser; } function getCommChoice(x) { comm = new Array("Compliment","Complaint","Feedback","Suggestion","Billing Query","Other"); var getsel = document.contactus.commlist.value; document.contactus.message.value = comm[getsel]; return document.contactus.message.value; } function sayThanks() { alert("Thank you for submitting"); return true; } </script> </head> <body> <form name = "contactus" method="post" onSubmit="return sayThanks()"> <table class='table_format_content_rbc' border='0'> <div> <span class='spn_big_lightblue_rbc'>RAINBOW</span><span class='spn_big_black_rbc'>CODE: CONTACT US </span> <td colspan='3' align='left' class='small_header_rbc'> <h3>Problems and general queries</h3> <li>Phone our call centre on 086 110 6472 ( Available 8am-5pm from monday-friday ) or</li> <li>Email us at <a href="mailto:helloise@pagesalive.co.za">feedback@miranetworks.net</a> </li> </td> </div> <div> <tr></tr> <tr></tr> <tr> <td colspan='3' align='left' class='small_header_rbc'> <h3>Frequently Asked Questions</h3> <li>Please take a moment to read the Frequently Asked Questions as the solution to your query could be waiting for you there!</li> <li>Have you read the <?php echo link_to('FAQ','util/faq') ?> ? <select id="yesnolist" onChange="getChoice(this.value)"> <option value="yes" selected="selected">Yes</option> <option value="no">No</option> </select> </li> </tr> <tr></tr> <tr></tr> </div> <div> <tr> <td colspan='3' align='left' class='small_header_rbc'> <h3>Feedback and Suggestions</h3> </select> </li> <textarea name="message" rows="10" cols="20"></textarea> <br /><br /> <?php $to = "helloise@pagesalive.co.za"; $subject = $_REQUEST["commlist"]; $email = $_REQUEST["emailreply"]; $message = $_REQUEST["message"]; $headers = "From: $email"; mail($to, $subject, $message, $headers); ?> <input type="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </div> </table> <table class='table_format_content_rbc' border='0'> <tr> <td colspan='3' align='left' class='small_header_rbc'> <br/> </td> <tr> </table> </form> </body> and also set the php.ini file portion: ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t and also ran: $ sudo echo "test" | mail -s "test" helloise@pagesalive.co.za The program 'mail' can be found in the following packages: * heirloom-mailx * mailutils please help?? <option value="feedback">Feedback</option> <option value="suggestion">Suggestion</option> <option value="billquery">Billing Query</option> <option value="other">Other</option> </select> </li> <textarea name="message" rows="10" cols="20"></textarea> <br /><br /> <?php $to = "helloise@pagesalive.co.za"; $subject = $_REQUEST["commlist"]; $email = $_REQUEST["emailreply"]; $message = $_REQUEST["message"]; $headers = "From: $email"; mail($to, $subject, $message, $headers); ?> <input type="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </div> </table> <table class='table_format_content_rbc' border='0'> <tr> <td colspan='3' align='left' class='small_header_rbc'> <br/> </td> <tr> </table> </form> </body> and also set the php.ini file portion: ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t and also ran: $ sudo echo "test" | mail -s "test" helloise@pagesalive.co.za The program 'mail' can be found in the following packages: * heirloom-mailx * mailutils please help?? Trying to send email to all users in db all works fine but it wont use my name or email. when i check inbox they are all from ****@cpanel42.uk2.net, i need it to look like, From: My Name - my@email.co.uk Code: [Select] <?php $dbhost = ''; $dbuser = ''; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db("", $conn); $name = "My Name"; $from = "my@email.co.uk"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1rn"; $headers .= 'From: '.$name.'<'.$from.'>'."\n"; $subject = "Subject"; $body = $message; $query = mysql_query("SELECT email FROM users") or die(mysql_error()); while(list($email) = mysql_fetch_row($query)) { mail($email, $subject, $body, $headers); } ?> I can get it to use just my email if i add "-f my@email.co.uk" but i really want to add my name Hi I am getting the following php error that is on all my pages and it works fine on the other pages except index.php Code: [Select] <?php session_start(); include 'includes/conn_db.php'; if (isset($_POST['submit'])) { if (empty($_POST['userName'])) { $u = FALSE; $nouser = '<font color="red" size="2" face="arial">You forgot to enter your username!</font>'; } else { $u = $_POST['userName']; } if (empty($_POST['userPassword'])) { $p = FALSE; $nopass = '<font color="red" size="2" face="arial">You forgot to enter your password!</font>'; } else { $p = $_POST['userPassword']; } $errorMessage = $nouser . "<br>" . $nopass; if ($u && $p) { $query = "SELECT * from clients WHERE email = '$u' AND pword = '$p'"; $result = mysql_query($query, $conn); while ($row = mysql_fetch_assoc($result)){ if ($u == $row["email"] && $p == $row["pword"]) { $query_name = "SELECT * FROM clients WHERE email = '$u' AND pword = '$p'"; $result_name = @mysql_query ($query_name); while ($row_name = mysql_fetch_assoc($result_name)){ $client_id_out = $row_name['client_id']; $firstname_out = $row_name['firstname']; $lastname_out = $row_name['lastname']; // Create sessions $_SESSION['client_id'] = $client_id_out; $_SESSION['firstname'] = $firstname_out; $_SESSION['lastname'] = $lastname_out; ob_end_clean(); header ("Location: myaccount.php"); exit(); }} } } } ?> <!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> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" /> <link href="layout.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="js/cufon-yui.js" type="text/javascript"></script> <script src="js/cufon-replace.js" type="text/javascript"></script> <script src="js/Futura_Bk_BT_400.font.js" type="text/javascript"></script> <script src="js/Futura_XBlk_BT_400.font.js" type="text/javascript"></script> <!--[if lt IE 7]> <script type="text/javascript" src="js/ie_png.js"></script> <script type="text/javascript"> ie_png.fix('.png'); </script> <![endif]--> </head> Thanks Lional Hi all, It's probably something obvious, but perhaps someone could explain to me what is going on here... I spent a lot of time this afternoon trying to fix what seemed to be a very odd problem, which involved an image being chucked out like so: Code: [Select] <?php header("Content-Type: image/png"); echo file_get_contents("http://www.example.com/some_image.png"); ?> Except the image was coming out as corrupted, ultimately because I had some white space before this snippet (foolish, I know). The reason it took me so long to diagnose the problem was because I wasn't getting PHP errors (even though they were switched on). As far as the script was concerned, it seems I wasn't sending anything before attempting to modify the headers. After solving the problem, I put the following little bit of code together, trying to force a header error... And yet I get nothing. It all works, and I get redirected, when I'm sure I shouldn't be. I've run this on a default install of XAMPP, and a configured CentOS server, and the same thing happens on both. If anyone can explain to me what is going on, I would be most appreciative! There are some inline comments which should help clarify what I mean. Code: [Select] <?php error_reporting(E_ALL); ini_set("display_errors","1"); ?> <p>Hello! The very existence of this text should really have resulted in the headers being sent... Shouldn't it?</p> <p>So I'd expect to see a "Headers already sent" message... Shouldn't I?</p> <?php // Headers sent? echo "<p>"; echo "Headers "; if(!headers_sent()) { echo "not "; // This "not" does echo out. } echo "sent.</p>"; // This WILL start a session (or at least, won't throw an error) session_start(); // This redirect WILL work, and you will never see the above messages. header("Location: redirect.php"); // What?! ?> Thanks! Dave hello, I'm using this code: <?php if (isset($_REQUEST['email'])) { $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $code = $_REQUEST['code'] ; $from = $email; mail("email@email.com", "Winner request id: $name - code: $code", "From:" . $from); } $headers = "From:" . $from; header('Location: index.php?done'); ?> And I'm getting: Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home/site/public_html/config.php:10) in /home/site/public_html/send.php on line 13 This worked before. Many thanks I have a form as a php include and it's giving me this error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/altimusw/public_html/www.csmsolution.com/register.php:6) in /home/altimusw/public_html/www.csmsolution.com/core.php on line 17 Here is the main page that includes the php include: <!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=iso-8859-1" /> <title>CSM Solution </title> <style type="text/css"> <!-- #Layer1 { position:absolute; left:100px; top:70px; width:800; height:62px; z-index:1; } .style1 { font-family: Arial, Helvetica, sans-serif; color: #535959; font-size: 12px; } --> </style> </head> <body> <div id="Layer1"> <table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="97"><img src="images/header.jpg" width="800" height="59" border="0" usemap="#Map" /><br /> <img src="images/navbar.jpg" width="800" height="38" border="0" usemap="#Map2" /> <map name="Map2" id="Map2"> <area shape="rect" coords="506,1,552,26" href="contact.php" /><area shape="rect" coords="459,1,502,26" href="form.php" /><area shape="rect" coords="396,-1,455,25" href="login.php" /> <area shape="rect" coords="357,0,393,26" href="index.php" /> </map> </td> </tr> <tr> <td><img src="images/welcome_img.jpg" width="131" height="21" /></td> </tr> <tr> <td><?php include("form.php"); ?></td> </tr> <tr> <td><img src="images/placeholderclouds_bottem.jpg" width="800" height="60" /></td> </tr> </table> </div> </body> </html> Here is the Core.php the error is referring to: <?php //CSM Solution Core. Rahul Parkar 2010 $_config = array(); $_config['db_type'] = "mysql"; $_config['db_server'] = "localhost"; $_config['db_username'] = "altimusw_csm"; $_config['db_password'] = ']17=rXh7tJ0~'; $_config['db_database'] = "altimusw_csm"; $_config['db_tbl_prefix'] = ''; $_config['user_table'] = "customers"; $_config['user_username'] = "username"; $_config['user_password'] = "password"; $_config['user_active'] = "approved"; $_config['user_role1'] = "prirole"; $_config['user_role2'] = "secrole"; $_config['pass_hash_func'] = "SHA1"; session_start(); function fetch_row($query) { build_connection($db); sql_exec($db, $query, $result); sql_fetchone($result, $row); finish_connection($db); return $row; } function build_connection(&$db) { global $_config; if ($_config['db_type'] == "mysql") { $db = mysql_connect($_config['db_server'], $_config['db_username'], $_config['db_password']) or die(mysql_error()); mysql_select_db($_config['db_database'], $db) or die(mysql_error()); } } function sql_exec(&$db, $query, &$result) { global $_config; if ($_config['db_type'] == "mysql") $result = mysql_query($query, $db) or die(mysql_error() . "/$query"); } function sql_fetchone(&$result, &$row) { global $_config; if ($_config['db_type'] == "mysql") { $row = mysql_fetch_assoc($result); @mysql_free_result($result); } } function sql_do(&$db, $query) { global $_config; sql_exec($db, $query, $noclue); finish_connection($db); } function finish_result(&$result) { global $_config; if ($_config['db_type'] == "mysql") @mysql_free_result($result); } function finish_connection(&$db) { global $_config; if ($_config['db_type'] == 'mysql') mysql_close($db); } function check_auth($username, $password) { global $_config; $row = fetch_row("SELECT `" . $_config['user_active'] . "`, `" . $_config['user_password'] . "`, " . $_config['pass_hash_func'] . "('" . $password . "') AS `passcheck`, `fname`, `lname` FROM `" . $_config['user_table'] . "` WHERE `" . $_config['user_username'] . "`='" . $username . "' LIMIT 1"); if (!$row[$_config['user_active']]) { return -1; } else { if ($row[$_config['user_active']] != 1) { return -2; } else if ($row[$_config['user_password']] == $row['passcheck']) { $_SESSION['username'] = $username; $_SESSION['fname'] = $row['fname']; $_SESSION['lname'] = $row['lname']; return 1; } else { return -1; } } } function load_access() { global $_config; if ($_SESSION['username']) { $row = fetch_row("SELECT `" . $_config['user_role1'] . "` FROM `" . $_config['user_table'] . "` WHERE `" . $_config['user_username'] . "`='" . $_SESSION['username'] . "' LIMIT 1"); $role1 = $row[$_config['user_role1']]; $_SESSION['role1'] = $role1; } else { return -1; } } function has_level() { for ($i = 0; $i < func_num_args(); $i++) { if (func_get_arg($i) == $_SESSION['role1']) { return 1; } } return 0; } ?> My error: Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/w/e/b/webaskius/htdocs/index.php:7) in /www/zxq.net/w/e/b/webaskius/htdocs/functions.php on line 6 Now, I can't quite figure out why it's doing this. The section of code that is causing this problem is above any HTML tags, at the very beginning of the file. <?php include('functions.php'); ?> <link href="style.css" rel="stylesheet" type="TEXT/CSS"> <img src="logo.png" border="0"> <div id="maincontent"> As you can see, the functions that cause this error are at the VERY beginning of my file. This is where they are called within index.php: if(mysql_num_rows($query_verify_login) > 0) { create_cookie(10000, 'user', $username); redirect('index.php'); } else { echo 'Woops! You\'ve entered in the wrong username and password combination!'; } And finally, my functions: <?php //our cookie creator function function create_cookie($time, $name, $data) { setcookie($name, $data, time()+$time); } function redirect($url) { header('Location: '. $url .''); } function get_replies($id) { //set query to find posts that match our id $query_get_replies = mysql_query("SELECT * FROM replies WHERE to = {$id}"); return mysql_num_rows($query_get_replies); } ?> Okay, I've read all the rules for Headers...still can't it to execute properly. At the bottom is my code. I basically want to check the database, see if the user is already registered, and redirect as appropriate (there is no HTML on my page, no info sent to the browser). My server doesn't send any error messages. All I get are white screens. Now, if I do the headers_sent()...it tells me that it's sent right after the initial connection with the database. The ONLY way I can get it to redirect, is if I put <?php header("location:index.php?msg=3"); ?> at hte very top, but then I can't evalute...which doesn't help me much. Here is the code (obviously, I have more...but it's sending headers in these lines) <?php $connection = mysql_connect("localhost","####","#####"); if (!$connection){ echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db("prixaurora")){ echo("Database not found<br>"); } I am trying to do a page redirect using the header() function.
I am aware that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
and also that reading code with include, or require, functions, or another file access function, can create spaces or empty lines that are output before header() is called. thus causing a redirect failure.
I have therefore used this output control function (ob_start(); ob_implicit_flush() right at the top of my page.
I am then creating the redirect like this as part of my login() function:
if($user_role == ADMIN_LEVEL || $user_role == EDITOR_LEVEL) { if (!headers_sent($filename, $linenum)) { return header("Location:http://mysite.com/dashboard.php"); exit; } else { echo "Headers already sent in $filename on line $linenum\n" . "Cannot redirect\n"; exit; } }Unfortunately I am still getting this error: Headers already sent in /home/steveoje/public_html/login.php on line 1 Cannot redirectAnd this is what I have at the top of the login.php page: <?php ob_start(); ob_implicit_flush(); require_once 'includes/config.php'; if(isset($_POST['submit'])) { login($_POST['username'], $_POST['password']); } require_once "includes/header.inc.php" ?> //other html contentSo why would the redirect fail in this instance? Thanks. Edited by terungwa, 28 September 2014 - 05:28 AM. Simple question. How do I redirect the header location on a session page. I thought I could go a different direction, but now I'm back to this one. I tried just adding header("Location: newpage.php") at the end of a query insert, but it gave me the warning that it can't modify the head. But I need the page to redirect after the query is done. Thoughts? I'm adding a login page to my website. When I go to the login page, and try to login, I keep getting the error "Warning: Cannot modify header information - headers already sent by (output started at C:\Users\me\Desktop\xampp\htdocs\site\login.php:7) in C:\Users\me\Desktop\xampp\htdocs\site\login.php on line 38" and I don't know why. I've looked into it, and from what I can tell its something to do with white spaces, but I cant find them. <?php include "./dbconnect.php"; ?> <?php forum_connect(); ?> <?php if(isset($_COOKIE['ID_forum'])) { $username = $_COOKIE['ID_forum']; $pass = $_COOKIE['Key_forum']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: main.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die(' <h2> You did not fill in all of the fields</h2> <p<a href="login.php">Return to login page</a> '); } if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die(' <h2> That user does not exist in our database.<br/> </h2> <p<a href="login.php">Return to login page</a> '); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) { die(' <h2> Incorrect password, please try again</h2> <p<a href="login.php">Return to login page</a> '); } else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_forum, $_POST['username'], $hour); setcookie(Key_forum, $_POST['pass'], $hour); header("Location: main.php"); } } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td><h2>Username:</h2></td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td><h2>Password:</h2></td><td> <input type="password" name="pass" maxlength="50"> </h2> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> Any help would be great Thanks Hi, I have a php email form and in the headers, I just want to add a 2nd email that the form will send to. I can only get the form to be sent to the first email? This is the code I currently have: $headers .= 'From: The Group <me@aol.com>' . "\r\n"; $headers .= 'CC: me2@aol.com'. "\r\n"; Is my code off for the CC email? Thanks for the help! Hi I have coded a form, and dependant upon the result I would like to re-direct to a different page. The problem is I am getting the "headers already sent" message..Is there a way around this, I can't use JS re-direction because of accessibility. E.G: <?php //Do stuff with form data if($result = y){ header(Location: "mysite.php/thankyou.php"); } else{ header(Location: "mysite.php/error.php"); } ?> In-fact whilst typing this I have an idea, why not do all of this at the top of the page before headers are sent? I'll go ahead and try it now, in the meantime if anybody knows how or if headers can be sent after output please let me know thanks. Hi;
I want to get the response headers using ob_get_contents ?
For example using file_get_contents, it is easy by accessing the variable $http_response_header like that :
<?php $content = file_get_contents($url); print_r($http_response_header); ?>But how to do that using ob_get_contents without a file_get_contents ? something like for example : <?php ob_start(); include($path_to_script_here); $string = ob_get_contents(); // Access the headers here ob_end_clean(); ?>Thank you Edited by Dareros, 07 October 2014 - 06:20 PM. I have an email generated from PHP but it's getting placed in gmails spam folder. Any idea how to get rid of my old domain from being displayed? Is this something I do in php or in ubuntu command line? If I have to change something in ubuntu, how do I edit the olddomainname. Here are the headers... Delivered-To: myname@gmail.com Received: by 10.204.7.18 with SMTP id b18cs39080bkb; Fri, 26 Aug 2011 10:18:41 -0700 (PDT) Received: by 10.90.21.11 with SMTP id 11mr1399661agu.42.1314379120253; Fri, 26 Aug 2011 10:18:40 -0700 (PDT) Return-Path: <www-data@mynewdomain.com> Received: from olddomain.com ([173.0.59.100]) by mx.google.com with ESMTP id d18si2778913anm.121.2011.08.26.10.18.38; Fri, 26 Aug 2011 10:18:39 -0700 (PDT) Received-SPF: pass (google.com: domain of www-data@mynewdomain.com designates 173.0.59.100 as permitted sender) client-ip=173.0.59.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of www-data@mynewdomain.com designates 173.0.59.100 as permitted sender) smtp.mail=www-data@mynewdomain.com Received: by olddomain.com (Postfix, from userid 33) id 339452F41206; Fri, 26 Aug 2011 13:18:31 -0400 (EDT) To: myname@gmail.com Subject: Closed Beta Invitation from My Name From: mynewdomain <contact@mynewdomain.com> Reply-To: ***** <contact@*****.com> MIME-Version: 1.0 Content-Type: text/html; charset=ISO-8859-1 Message-Id: <20110826171831.339452F41206@*****.com> Date: Fri, 26 Aug 2011 13:18:31 -0400 (EDT) ok i read the header part but i sure i did it rite but its givong me those erros Code: [Select] <?php session_start(); $username = $_SESSION['username']; ?> <?php require "scripts/connect.php"; if($_POST['submitbtn']){ $body = mysql_real_escape_string($_POST['area1']); if($body){ $query = mysql_query("UPDATE history SET body ='$body'"); echo $msg = "UPDATED GOOD"; header('location: http://www.rbrhslsp.org/rbrhsadmins/edithistory'); }else $msg = "Please fill in the body"; } mysql_close(); ?> <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM history"); $rows = mysql_fetch_assoc($query); $body = stripslashes($rows['body']); mysql_close(); ?> <?php require "header.php"; ?> <?php if ($username){?> <div id="leftContent"> <h4> Your page </h4> <?php echo $msg;?> <form action='edithistory' method='post'> <textarea style="height: 100px; width:490px;" name="area1" cols="58"><?php echo $body;?></textarea> <input type='submit' name='submitbtn' value='Submit' /> </form> </div> Hi All, I am trying to use headers at the end of functions to put the user where they need to be. header("location: register.php?user_may_exist"); I understand how they work and their qwuirks. My issue is, in my head file, i am outputting which causes issues for the headers which come after. I have the following in head.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> <?php if(isset($currentPageTitle)){ echo $currentPageTitle; }else{ echo 'Cricket Club'; }; ?> </title> <?php if(isset($currentPageMeta)){ echo "<meta name='description' content='$currentPageMeta'>"; }else{ echo "<meta name='description' content='All the latest from CC'>"; }; ?> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Is there a better way for me to achieve this? Hi Guys
I have recently been looking into implementing browser caching after reading this: https://developers.g...ctices/cachingĀ
There are a few things in that google article that don't make much sense to me so I'm hoping someone can clarify.
Firstly Question
The document says:
" we recommend that you configure your web server to explicitly set caching headers and apply them to all cacheable static resources"
This implies you can set caching headers for just some resources. How would you do this? Lets assume I only wanted to set caching headers for a file styles.css - would I need to output headers within the CSS file and then change the extension to .php? e.g.
<link rel="stylesheet" href="styles.php"/>Second question Etags have me very confused. How would you set etag headers for specific files and then generally? And if you set the etag in the header of the main php page does that mean everything gets cached? Any help someone can provide would be very, very welcome! Drongo OK you fantastic PHPfreakers I'm not sure how to describe this so I hope you will understand..
I have a predicament where I set the header info to: header('Content-Type: text/html; charset=utf-8'); but later on I have a part of my site that requests an image from somewhere else using getImage() here I need to set header("Content-type: image/jpeg"); in order for the image to show correctly. but this conflicts with the previous page of headers already sent.
so I was looking for a way around this OR maybe can I load them in after the page has loaded? I have tried using Jquery to post with ajax but I don't seem to get any response the alert does not trigger for any conversation with an image.
I have tested all of this and it works as long as I don't put any OUTPUT before triggering the getImage()
<script type='text/javascript'> $(document).ready(function(){ function loadImages(){ $.ajax({ type: "POST", url: "/admin/getImage.php", data: {token: '<?php echo $token; ?>', chatId: '<?php echo $chat; ?>', uId: '<?php echo $uId; ?>'}, success: function(data){ alert(data); $('#img').html(data); } }); return false; } }); </script>here is part of the messages page that would show the image. (just imagine there was more content etc..) <?php header('Content-Type: text/html; charset=utf-8'); ## OTHER GENERIC STUFF $parser = new Parser($v1, $v2); $convo = $parser->getConvo($token, $id); foreach($convo['messageGroups'] as $con) { $chat = $con['messageGroupId']; $uId = $con['latestMessage']['messageUid']; $key = $con['latestMessage']['messageKind']; if($key == '3'){ $image = $parser->getImage($token, $chat, $uId); echo $image; } } ?>here is the function for getImages() public function getImage($token, $chat, $uId){ $this->initCURL(); $chatter = str_replace("{{chat}}", $chat, $this->url['image']); $chatter = str_replace("{{uId}}", $uId, $chatter); $headerData = $this->defaultGETHeader($token); curl_setopt($this->curl, CURLOPT_URL, $chatter); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headerData); $output = curl_exec($this->curl); $this->closeCURL(); header("Content-type: image/jpeg"); return $output; } Edited by xXREDXIIIXx, 01 June 2014 - 12:18 PM. |