Thread: If Statements

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    47
    Rep Power
    3

    If Statements


    I am trying to setup a redirect on a page for people who visit using a ipad. The iPad info is correct, as I am able to use echo and it will display a message. I am wanting to just redirect the user though. This is the code I am using, but for some reason it will not redirect me.

    PHP Code:
    <?php $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); 
    if (
    $isiPadheader"Location: http://www.google.com" ); ?>
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,870
    Rep Power
    6351
    You must die() after a header call, but that may not be it.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    47
    Rep Power
    3

    Solved


    Originally Posted by Smurff289
    I am trying to setup a redirect on a page for people who visit using a ipad. The iPad info is correct, as I am able to use echo and it will display a message. I am wanting to just redirect the user though. This is the code I am using, but for some reason it will not redirect me.

    PHP Code:
    <?php $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); 
    if (
    $isiPadheader"Location: http://www.google.com" ); ?>

    This is correct. It was not working because I had this in the <body> instead of <head> ... Im guessing? No other php code is/was on the page at the time.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,870
    Rep Power
    6351
    So...you fixed it?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Originally Posted by ManiacDan
    So...you fixed it?
    It looks like it although from my understanding, a header() statment should come before ANYTHING else on the web-page, HTML markup and whitespace included.

    Maybe that's what was stopping it from working, you had "<html><head> .... html code here </head><body>" and THEN the PHP header()?

    I always thought that it should be before ALL of that?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,870
    Rep Power
    6351
    I guess the "for some reason" meant "a very clear error message specifying the exact problem, how to fix it, and file names with line numbers."
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    47
    Rep Power
    3
    "For some reason" meant the PHP code is correct, however it is not working as it should.


    Yes I fixed the problem by moving the php code higher up on the webpage. I had it in <html><head><body> PHP CODE </body></head></html>

    It works fine being in the <head> section. I would move it higher, except I am using dreamweaver and have this page as part of a template, so the first editable region available (without having to create another one) was in the head.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    170
    Rep Power
    54
    Originally Posted by Smurff289
    <html><head><body> PHP CODE </body></head></html>
    I hope this structure was just a quick typo.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    47
    Rep Power
    3
    LOL! yeah my bad. nice catch. But you got the point.

    <html> <head> </head> <body> PHP CODE </body> <html>
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,870
    Rep Power
    6351
    You have your errors turned off. A very exact and easy to read error is thrown when you use header() wrong.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0
    Originally Posted by ManiacDan
    So...you fixed it?
    is it fixed?

IMN logo majestic logo threadwatch logo seochat tools logo