+ Reply to Thread
Results 1 to 10 of 10

Thread: PHP header location not working on X10hosting

  1. #1
    sikuneh is offline x10Hosting Member sikuneh is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    43

    PHP header location not working on X10hosting

    I am trying to use the php header("Location:url") to redirect a user to a login page if they have not logged in yet. It works fine on my local copy but on X10 the redirect does not work. Is there some setting which does not allow PHP header or something on the X10 servers?

  2. #2
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: PHP header location not working on X10hosting

    Anything that plays with the HTTP headers has to come first in the file (that is, no text or HTML can be sent before the headers). There can be no data -- not even white space -- before the opening <?php tag, and you can't echo anything before setting the headers.

    You may have a problem with a Byte Order Mark in your file -- an invisible, unprintable character that will appear as the first two bytes of a Unicode text file to tell the system whether the file uses Big-endian or Little-endian byte orders. If you are suppressing errors, you will not be told about the "headers already sent" error, but any custom headers you try to send will not be sent.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  3. #3
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: PHP header location not working on X10hosting

    Paste your script. It's a bug in the script - header location works fine for me.
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  4. #4
    sikuneh is offline x10Hosting Member sikuneh is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    43

    Re: PHP header location not working on X10hosting

    I'm pretty sure it is what essellar said, although, I have the header on an included file so the header functions way down the line in the preproccessor when the page loads. Is there a workaround for this or a different way to work this?

  5. #5
    ellescuba27 is online now x10 Sophmore ellescuba27 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    151

    Re: PHP header location not working on X10hosting

    No, headers must be before any html.

    Let me explain: When a computer goes to a website, it doesn't know what's on it, so it asks your server (which is what you get when you sign up for x10) "Hey, what's on this site?" And the server replies "Here's what's on the site!" So for example, when going to Gmail, the computer asks a Gmail server "Hey, what's on this site?" and the server answers "Ok, well here's the compose button, and here's the settings" and so on and so forth. All of this is done before the page loads. PHP is a special language. It changes what the server says to the computer. So maybe, when the computer asks "Hey, what's on this site?" the server might check if a user is logged in or not. If he is logged in, it will say "This button should be green" but if he's not, the server says "This button should be Red". That's what PHP does.

    But what if your computer wants to go to another page, before the server tells you what's on this one? There is only ONE WAY that the computer can tell the server what to do. In order for the computer to tell the server what to do, the computer must use a header. A header is ALWAYS placed before html, because otherwise, the server will have already started telling the computer what to do, and the computer won't have a chance to tell the server what to do. So a proper header should ALWAYS be before html. So should cookies and sessions, because they both require a header to work. In this case, you are using a header, so it should be before the <html> tag.

    Hope that solves your problem.

  6. #6
    sikuneh is offline x10Hosting Member sikuneh is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    43

    Re: PHP header location not working on X10hosting

    Yes, I understand that part. I suppose there's no workaround in the way I described. But I think the way I'll do it is to have the link send me to a page that isn't included, then redirect it to the included pages based on the if statement on the top. Thanks.

    I do have a second question: why does it work on my WAMP server?

  7. #7
    ellescuba27 is online now x10 Sophmore ellescuba27 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    151

    Re: PHP header location not working on X10hosting

    No idea, but it shouldn't. Same problem here with XAMPP.

  8. #8
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP header location not working on X10hosting

    You haven't even described what you mean by "doesn't work".

    If you give a URL that shows the problem, we can see it first hand.
    Nothing is always absolutely so.

  9. #9
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: PHP header location not working on X10hosting

    The reason why WAMP doesn't throw the error is because output buffering is enabled by default in the php.ini. You don't have access to the php.ini here (or in most shared hosting environments), but you can modify your scripts to include output buffering by adding the lines:

    PHP Code:
    <?php
    ob_start
    ();

    //everything else goes here

    ob_end_flush();
    ?>
    to all of your "host" pages (not the included or required pages). That is not the optimal solution though -- it would be far better to turn off output buffering in your local php.ini. That will cause the "headers already sent" error to happen in your WAMP development/testing environment, which will then force you to write your scripts in a way that is easily deployable to any host.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  10. #10
    sikuneh is offline x10Hosting Member sikuneh is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    43

    Re: PHP header location not working on X10hosting

    Ok, thanks for the info. I fixed it on my local copy.

+ Reply to Thread

Similar Threads

  1. Header not working *MOVED*
    By scorch94 in forum Programming Help
    Replies: 11
    Last Post: 10-08-2011, 02:16 PM
  2. Replies: 2
    Last Post: 06-14-2010, 12:03 PM
  3. Co.cc and x10hosting not working together.
    By smartflight in forum Free Hosting
    Replies: 5
    Last Post: 02-16-2010, 04:03 AM
  4. Header Location Problem
    By xevell in forum Free Hosting
    Replies: 7
    Last Post: 07-15-2008, 09:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers