Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: PHP Help

  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default PHP Help

    Is it possible to set a page to redirect but with code before it in PHP? The only way I know of is using header(); but I need to specify a variable first. I don't want the redirect to show up in source either so no JS or HTML redirects.

    Edit by Robbie! (Forum Moderator) - Moved to Coding. Please post in the corerct section next time.
    Last edited by Robbie; 02-01-2009 at 05:24 PM.
    Vouches
    [x][x]

  2. #2
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    You can do whatever you want before the header(), as long as there's no output.
    So specifying the variable shouldn't be affected.

  3. #3
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
    echo 'hi lawl!!!!!!!!2';
    header'Location: http://www.ggg.com/' );

    // The above won't work.

    header'Location: http://www.ggg.com/' );
    echo 
    'hi lawl!!!!!!!!!!2'// Remember, this won't be shown anyway.

    // Will work, you can escape outputs easily with if statements etc.

    if( $variable !== 'null' )
    {
    echo 
    'hi lawl!!!!!!!!!!2';
    }
    else 
    {
    header'Location: http://www.ggg.com/' );
    }
    ?>

  4. #4
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Ah, I didn't know that. Thanks and +rep
    Vouches
    [x][x]

  5. #5
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Fazon View Post
    Ah, I didn't know that. Thanks and +rep
    Glad I could help.

  6. #6
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    PHP Code:
    <?php

    echo "Single quotes are normally for 1 word strings";
    header"location:http://blah.com/" );

    //the above won't work

    header"location:http://www.ggg.com/" );
    echo 
    "Single quotes are normally for 1 word strings";

    // won't work as the page is terminated after the headers are sent
    // you can however do it this way

    if( $variable !== NULL ) {
         echo 
    "somethingbing";
    } else  {
         
    header"location:http://www.ggg.com/" );
    }

    ?>
    Welcome to the world of indentation calon, ref strings/variables I always think its better to use "" on strings with more than a single word etc, I may be mis-informed. Location though, does not have a capitol L and looks extremly messy.


    www.fragme.co = a project.

  7. #7
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    Na, I disagree Matt

    Personal preference. I use two ' when It's plain text/html. I barely use "".

    But yeh personal prefs

  8. #8
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    But surely in situations

    echo "Hello there {$name}, how are you? Today is {$today}";

    its better than

    echo 'Hello there ' . $name . ' how are you? Today is ' . $today ;


    www.fragme.co = a project.

  9. #9
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Jackboy View Post
    Na, I disagree Matt

    Personal preference. I use two ' when It's plain text/html. I barely use "".

    But yeh personal prefs
    Could be a security risk. If you don't use ENT_QUOTES with htmlspecialchars then they remain the same, so if you have BBCode then users can add their own attributes, such as onMouseOver.

    I've always put a capital L on Location, I thought that was normal.

  10. #10
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Jxhn View Post
    Could be a security risk. If you don't use ENT_QUOTES with htmlspecialchars then they remain the same, so if you have BBCode then users can add their own attributes, such as onMouseOver.

    I've always put a capital L on Location, I thought that was normal.
    Lol I was talking about html output as in the html I DO, not what the user does. Thanks though babes.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •