garyed Posted February 5, 2014 Share Posted February 5, 2014 (edited) I've solved this problem but I was just wondering if this is version specific. On my Apache server this code works fine exactly where it is in the file: $name= $_POST['name']; if ($name=="") { header("Location:index.php"); } but when I upload the page to my website it doesn't. I had to move those lines to the beginning of the file in order for the redirection to work. My server is using: PHP Version 5.3.2-1ubuntu4.7 My web host is using: PHP Version 5.4.24 I had a similar problem with sessions where the same file would work on my server but not on my website without doing some editing. The versions are very close but does this mean that the php version on my server is just more forgiving? Edited February 5, 2014 by garyed Quote Link to comment Share on other sites More sharing options...
.josh Posted February 5, 2014 Share Posted February 5, 2014 Not enough code/info to go off of. It may be because of error level settings vs. what you're outputting and when. In general, you can't output headers before any other output, and for a Location header specifically, it should immediately be followed by exit(); if you don't want the rest of the code to execute. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 5, 2014 Share Posted February 5, 2014 Have you enabled php error checking to see if there is something else in your script that causes the problem? BTW - I believe that the syntax is very specific: "Location: " must have a trailing space. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 5, 2014 Share Posted February 5, 2014 your development system as a (nasty) php setting turned on that allows poorly written code to work, but makes it non-portable between servers. you need to turn off output_buffering in your php.ini on your development system so that the code you produce will work, with respect to header() statements (which sessions also use for the session id cookie), regardless of the server you try to run your code on. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 5, 2014 Share Posted February 5, 2014 BTW - I believe that the syntax is very specific: "Location: " must have a trailing space. Works without the space for me Quote Link to comment Share on other sites More sharing options...
requinix Posted February 5, 2014 Share Posted February 5, 2014 Works without the space for me Yup. Whitespace is recommended (a single space) but not required. Quote Link to comment Share on other sites More sharing options...
garyed Posted February 6, 2014 Author Share Posted February 6, 2014 your development system as a (nasty) php setting turned on that allows poorly written code to work, but makes it non-portable between servers. you need to turn off output_buffering in your php.ini on your development system so that the code you produce will work, with respect to header() statements (which sessions also use for the session id cookie), regardless of the server you try to run your code on. I found a line in my php.ini file that says "output_buffering=4096 " Is that what you're talking about? Do I just put a # in front of the line or put a 0 in place of the 4096 to turn it off or is there something else i need to do? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 6, 2014 Share Posted February 6, 2014 set it to - output_buffering=off you will need to restart your web server to get the change to take effect. Quote Link to comment Share on other sites More sharing options...
Solution garyed Posted February 8, 2014 Author Solution Share Posted February 8, 2014 Thanks for all the help, I set the output_buffering to off and that made my home server work like my webhost server. So using output_buffering allows for poorly written code to get by? I don't get it, what's the real purpose of the setting? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 8, 2014 Share Posted February 8, 2014 (edited) I don't get it, what's the real purpose of the setting? see below - So using output_buffering allows for poorly written code to get by? it also hides error messages and helpful messages your application might be outputting. Edited February 8, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Barand Posted February 8, 2014 Share Posted February 8, 2014 I have found it useful in the past to buffer the output from a php page then save that output to a static html file. I can then email the sample output to a client for approval/comments while still under development on my local pc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.