Jump to content

header("Location:") works on some versions


garyed
Go to solution Solved by garyed,

Recommended Posts

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 by garyed
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Solution

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.