PHP - Header Location, Issue. Small Piece Of Code, Can Anyone Take A Look
My Error Output is this:
Warning: Cannot modify header information - headers already sent by (output started at city-search.php:1) in city-search.php on line 65 What I'm I missing in the code, I can't seem to get these. It works excellent in Localhost, but in production. Error above. Code: [Select] <?php // MG CREATED THIS SIMPLE REGISTRATION PHP FOR THAT GOES TO ONE SPECIFIC USER. // WILL TEST FORM REGSITRATION NG 07-2011 //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) == '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { //$hasError = true; $comments == 'Have No Friends'; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { //$emailTo = 'regina@shushmedeals.com'; //$emailTo = 'reginabyrd32@yahoo.com'; $emailTo = 'mp3@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //$emailBcc = 'info@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //Put your own email address here $body = "Location: $name \n\nEmail: $email \n\nShushMeDeals Sign-up Info:\n $comments"; // To send HTML mail, the Content-type header must be set $headers = 'From: ShushMeDeals.com City Location sign-up - '.$name.'' . "\r\n" . 'Reply-To: ' . $email . "\r\n" .'Bcc: print@extremeatlanta.com'; //$headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; //$headers .= 'Bcc: info@danjaproduction.com' . "\r\n"; mail($emailTo, $subject, $body, $headers); $emailSent = true; if($emailSent = true) { setcookie("location", $name); //echo '<script type="text/javascript"> // window.location = "index.php?option=com_enmasse&controller=deal&task=today&locationName='.$name.'" // </script>'; } } } ?> Similar TutorialsCode: Code: [Select] <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> Error: Code: [Select] Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\sources\admin\manage-user.php on line 26 Sorry, im a noob when it comes to coding. please help! Helo dear people, I need some help with piece of code that generates XML This all works as is: Code: [Select] include(dirname(__FILE__).'/config/config.inc.php'); require_once(dirname(__FILE__).'/init.php'); error_reporting(0); $p=Product::getProducts(7, 0, 0, 'id_product', 'desc', false); $products=Product::getProductsProperties(7, $p); header("Content-Type: text/xml\n\n"); //print "Content-type: text/html\n\n"; echo '<?xml version="1.0" encoding="utf-8"?> <Catalog>'; foreach ($products as $row) { if ($row['active']){ $img=Product::getCover($row['id_product']); echo ' <products> <code>'.str_replace("&", "&", $row['id_product']).'</code> <name>'.str_replace("&", "&", $row['name']).'</name> <descr>'.str_replace("&", "and", strip_tags($row['description_short'])).'</descr> <price>'.($row['price']*1).'</price> <quantity>'.str_replace("&", "&", $row['quantity']).'</quantity> <categ>'.str_replace("&", "&", $row['category']).'</categ> <link>http://www.xxxxx.hr'.$row['link'].'</link> <img>http://www.xxxxx.hr/xxxxx/'.$shopUrl.'img/p/'.$row['id_product'].'-'.$img['id_image'].'.jpg</img> </products>'; } } echo '</Catalog>'; ?>code] :shrug: But now i need to hide quantity if its larger that 5 pieces. So that all quantity that is >= equal or larger of 5 si shown in XML as 5. Can anyone help me out with this!? :'( BR Vixus I have the below code: Code: [Select] $buttons = "button+='<table height=\"40\" border=\"0\"id=\"table1\"cellspacing=\"0\"cellpadding=\"2\"><tr><td>---PLACE CODE HERE---</td><td valign=\"bottom\">';\n"; between the to cell tags (<td>---PLACE CODE HERE---</td>) I need to add this code: Code: [Select] document.getElementById('com').innerHTML=<?php echo $gSurfMultiLoadedText; ?>+button2; My problem is the '; " and \" stuff Anyone care to show how I can merge these pieces? I was wondering if it's possible to retain loaded files and the current error setttings after a
header("Location: xxxx.php")is issued, for example in this: // Start up the session - not used yet but there just in case session_start(1); // Enable the Autoloader and initialise it require_once 'Autoloader.php'; Autoloader::init(); // Check if the application has been installed yet ---------------------------- if(!file_exists('Engine/config.php')){ session_write_close(); header("Location: install/index.php"); die(); }And I get a class not found error when I open the install/index.php session_start(1); // @todo: Disable this in the production version .... I already did this in the main index -- do I have to do this on all pages that may error? error_reporting(E_ALL & ~E_STRICT); ini_set("display_errors",1); // Because we jumped here, we have to reinstall the autoloader -- why? require_once '../Autoloader.php'; Autoloader::init();While I can understand I wouldn't want this if I was firing off to a completely different site, is there anyway to retain the settings within the same server environment or do I have to reset everything as above. I even tried using session in the hope that this would 'remember' but it didn't work. I have this little code that I cannot get to work Code: [Select] $sql_buildings = ("SELECT castle, treasury, huts, [b]leader_id[/b] FROM teams WHERE team_id=[b]".$_GET['t']." [/b]"); $rsbuildings = mysql_query($sql_buildings); if($rsbuildings[".$_GET['t']."] == 'leader_id' ){ The problem is this part: Code: [Select] if($rsbuildings[[b]".$_GET['t']."[/b]] == '[b]leader_id[/b]' ){ How can I write it to have these to values work?
Hi there, i have an code <?php $a = [ 0 => 10, ]; $i = 0; $a[$i++] = $i;
and question "Explain what the problem is and what you could do to fix it"
Please help! Hi, Im new to all this coding stuff but get by ok with help from the wealth of info on the internet however in this instance i cant solve a PHP redirect issue im having. Ive got a very simple php script to redirect to a secure paypal item link using the header function. header("Location:https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XYX96W3MSFQZ6"); The problem is when the script is called upon in IE it loops endlessly however works perfectly in Chrome, Firefox, Opera and the Andriod stock browser. I originally tried the redirect directly within the meta tag although this failed on all browsers so now i have the meta tag point to this PHP file. (The meta tag is in a script that submits form data and displays a temporary 'redirecting...' page. Has anyone expirenced this problem before or know of ways to fix it for IE? Could it be an issue with security in IE because the paypal link is secure? Any help would be greatly appreciated. this little piece of code doesn't seem to work: Code: [Select] if($rs_teamcheck['team_id'] != $team{ header( "Location: http://domain/page.php" ) ;} If I replace the header location part with an echo the output is fine, so why isn't the redirect working? I've made a Login Script and I'm trying to make it re-direct me to the Homepage after the login is complete. However, it's doing nothing at all... Code: [Select] <?php require('./includes/header.php'); require('./includes/functions.php'); ?> <div id="loginHolder"> <div id="title"></div> <h2>Login</h2> <hr /> <?php if(@$_POST['submit_login']) { echo '<div id="loginBox">'; $username = protect($_POST['username']); $password = protect(encrypt($_POST['password'])); $loginCheckQ = mysql_query("SELECT * FROM `users` WHERE `username`='".$username."'"); $loginCheckF = mysql_fetch_assoc($loginCheckQ); $dbusername = $loginCheckF['username']; $dbpassword = $loginCheckF['password']; if($username == $dbusername && $password == $dbpassword) { $_SESSION['loggedUser']=$username; echo '<font color="green">You have successfully logged in as '.$username.'.</font>'; header('location: index.php'); } else { echo '<span>Incorrect Username or Password.</span>'; } echo '</div>'; } ?> <form action="login.php" method="POST" autocomplete="off"> <table cellspacing="0" cellpadding="0"> <tr> <td>Username: </td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password: </td><td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="Login" class="submit" name="submit_login" /></td> </tr> </table> </form> </div> <?php require('./includes/footer.php'); ?> It works perfectly fine on Localhost, but when I upload it, it doesn't work. 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 everyone. I want to use php to obtain the 'location' value from a header of a url. However, when I use get_headers() it automatically follows the redirect and gives me the header information of the new page. I don't want this, I need the headers of the original page. (I need the value of the 'location' variable in the header). Hope you can help me out. Hi Everyone, I'm having a bit of a problem if someone could help me with? I have a simple registration form with fields userid, username, password, clientaddress So when the user logs in with their username and password it will redirect to their client address but I cant get the redirect working. Here is my code: Code: [Select] $clientaddress = trim($_POST['clientaddress']); $_SESSION['start'] = time(); header("Location:$clientaddress"); exit; } also note if I add: Code: [Select] $clientaddress = 'http://www.google.com'; it redirects ok to google. It's getting the field from the database I think thats the problem Can somone help it just wont redirect to the client address I am past a beginner in php but no where near an expert and I need some help. This piece of code he $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); is part of my search results page with paged indexes (next, previous 10, etc.). However with this code i get the die message but if i take the first line off ($query), the page executes but then the page doesn't operate correctly i.e. shows 15 results when the $limit(limit for rows) =10. Is it not written correctly or am I missing somethingwith the top line? if the entire script is needed let me know and i will paste it? Thanks in advance for any help! I'm using jQuery ajax for my login script. However my linked php file with ajax doesn't change the screen with header('location') whats a way to change the page on login using ajax? Thanks So I have a site in which a user logs in. When they click the submit button on the login page, it checks to see if a username and password combo exists in an array. If it doesn't exist, the user is supposed to be redirected back to the login page.
This code USED to work, and I think I added one thing completely away from the code that should do any of this, but now it doesn't work any more.
I've read that you can't have anything output before the header code, so I've double checked, and can't find any spaces, echo statements or anything of the like. I've thrown in a random echo statement to see if my if's else's were being entered correctly, and they are. I definitely get into the else statement with the header(location: blah) code when an incorrect username/password is used...
Here's the code I'm looking at. (And there is More HTML under this...)
<?php session_start();?> <?php include("passwords.php"); //this statement will be entered if coming from the login.php page. if ($_POST["ac"]=="log"){ //check if submitted username and password exist in $PASSWORD array if ($PASSWORD[$_POST["username"]]==$_POST["password"]){ //set various session variables $_SESSION["username"]=$_POST["username"]; $_SESSION["firstname"]=$FIRSTNAME[$_POST["username"]]; $_SESSION["lastname"]=$LASTNAME[$_POST["username"]]; $_SESSION["email"]=$EMAIL[$_POST["username"]]; } else{ //if username and password do not exist, set session variable for "incorrect username/password" message and redirect to login.php $_SESSION['incorrect'] = "incorrect"; header('Location: login.php'); }; }; // check if user is logged in already when they are coming from a random place. If not, redirect to login.php check_logged(); ?>Any ideas out there why my header('Location: login.php'); line is not working? I'm trying to rewrite the old jpmaster77 login script that I used back in the day quite extensively, but I'm having problems getting the $form->error messages to the correct page.
Login form, on the index.php:
<div> <h3>Login</h3> <form method="post" action="process.php" id="sublogin"> /* error message should be displayed here when username is empty or == username */ <p> <?php echo $form->error("user"); ?> <input class="loginside" type="text" name="user" value="username" /> ?> <br /> <input class="loginside" type="password" name="pass" value="password" /> <br /> <input type="hidden" name="sublogin" value="1"> <input type="checkbox" name="remember">Remember me <br /> <input class="sublogin" type="submit" value="login" style="border: 0; margin: 5px 0 0 1px;" /> </p> </form> Not registered yet? Sign up here! </div> process.php class Process { /* Class constructor */ function Process(){ global $session; /* User submitted login form */ if(isset($_POST['sublogin'])){ $this->procLogin(); } /** * Should not get here, which means user is viewing this page * by mistake and therefore is redirected. */ else{ header("Location: index.php"); } } function procLogin(){ global $session, $form; /* Login attempt */ $_POST = $session->cleanInput($_POST); $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember'])); if($retval){ header("Location: correct.php"); } else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: index.php"); } /* if instead the $_SESSION and header I enter echo $form->error("user") then the error message is displayed in process.php, and not in index.php */ } } $process = new Process; ?>But when instead the $_SESSION and the header location I enter here echo $form->error("user"); then all is fine. But the error message should not be displayed in the process.php, but rather above the login form on the index.php session.php <?php include "database.php"; include "form.php"; class Session { var $time; function Session(){ $this->time = time(); $this->startSession(); } function startSession(){ $session_name = 'sec_session_id'; // Set a custom session name $secure = true; // This stops JavaScript being able to access the session id. $httponly = true; // Forces sessions to only use cookies. if (ini_set('session.use_only_cookies', 1) === FALSE) { header("Location: ../error.php?err=Could not initiate a safe session (ini_set)"); exit(); } // Gets current cookies params. $cookieParams = session_get_cookie_params(); session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); // Sets the session name to the one set above. session_name($session_name); session_start(); // Start the PHP session session_regenerate_id(true); // regenerated the session, delete the old one. } function login($subuser, $subpass, $subremember) { global $database, $form; /* username check */ $field = "user"; if(!$subuser || $subuser == "username") { $form->setError($field, "* Username incorrect"); } /* password check */ /* if e-mail welcome, check if user activated account */ /* Return if form errors exist */ if($form->num_errors > 0){ return false; } return true; } function cleanInput($post = array()) { foreach($post as $k => $v){ $post[$k] = trim(htmlspecialchars($v)); } return $post; } }; $session = new Session; $form = new Form; ?> form.php <?php /** * Form.php * * The Form class is meant to simplify the task of keeping * track of errors in user submitted forms and the form * field values that were entered correctly. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 19, 2004 */ class Form { var $values = array(); //Holds submitted form field values var $errors = array(); //Holds submitted form error messages var $num_errors; //The number of errors in submitted form /* Class constructor */ function Form(){ /** * Get form value and error arrays, used when there * is an error with a user-submitted form. */ if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){ $this->values = $_SESSION['value_array']; $this->errors = $_SESSION['error_array']; $this->num_errors = count($this->errors); unset($_SESSION['value_array']); unset($_SESSION['error_array']); } else{ $this->num_errors = 0; } } /** * setValue - Records the value typed into the given * form field by the user. */ function setValue($field, $value){ $this->values[$field] = $value; } /** * setError - Records new form error given the form * field name and the error message attached to it. */ function setError($field, $errmsg){ $this->errors[$field] = $errmsg; $this->num_errors = count($this->errors); } /** * value - Returns the value attached to the given * field, if none exists, the empty string is returned. */ function value($field){ if(array_key_exists($field,$this->values)){ return htmlspecialchars(stripslashes($this->values[$field])); }else{ return ""; } } /** * error - Returns the error message attached to the * given field, if none exists, the empty string is returned. */ function error($field){ if(array_key_exists($field,$this->errors)){ return "<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>"; }else{ return ""; } } /* getErrorArray - Returns the array of error messages */ function getErrorArray(){ return $this->errors; } }; ?>Does anyone know why the $form->error("user") variable cannot be transfered to the index.php? Is something wrong with the session_start or something? thanks in advance guys! Edited by dde, 07 January 2015 - 03:49 PM. I have a form, where I'm collecting registration info - like name, address, email, password. I'm calling another php file at server side code, where it will check whether the email exists or not. Pretty simple, just receiving those post variables and check with the database. The issue, if I find a match, I want to go back to the registration.php page, using the following code: if ($email_already_use == "y") { $_SESSION['ERROR'] = "Error"; $_SESSION['MESSAGE'] = "This email address already used. Please try another"; header("location: ".$settings['site_url']."registration.php"); exit; } Now, I would like to place the user input at the registration.php file, but I do not want to use pass variable at URL like this: header("location: ".$settings['site_url']."registration.php?".name=$name&address=$address&email=$email; Is there anyway, I can retrieve those variables at registration.php, without specifying .name=$name&address=$address&email=$email ? Thanks for your help. I see some sites has similar implementation, but did not find anything like how to do it. Hello, When i want a custom site search i need to process like google "site:600host.net terms" however my php just pulls a blank page when trying to output this i think its to do with : Quote <?php $keywords = $_REQUEST["keywords"]; $keywords2 = "$keywords"; $lowerCase = strtolower($keywords2); header("Location: ".$lowerCase.".html"); ?> Thanks any help appreciated! Hi, I have a div which reloads every 10 seconds but I want it so that if it equals something then redirect the whole page when at the moment it just loads the whole page in in the div but need the div as it stores all my variables, anyone know of anything else I can use? Thanks I want the page to refresh on with the query string, but this isn't working for me... Code: [Select] header("Location: " . $_SERVER['php_self'] . "?" . $_SERVER['query_string'] ); |