Help with one line of php

Discussion in 'PHP' started by daryo, May 23, 2008.

  1. #1
    Hy guys,
    I want to make a redirect.php page.
    I want to make it like this :
    redirect.php?url=http://site.com
    So when you enter that url it redirects to http://site.com

    What's the piece of code to use ?
    I tried this but it's not working :
    <?php header("Location: $_GET['$url']"); ?>
    PHP:
    Can you help me please ? Thanks
     
    daryo, May 23, 2008 IP
  2. biobrain

    biobrain Peon

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    biobrain, May 23, 2008 IP
  3. daryo

    daryo Well-Known Member

    Messages:
    1,343
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thanks, but that's not what i need.
    I want it to dynamic redirect to any url you enter after ?url=
     
    daryo, May 23, 2008 IP
  4. biobrain

    biobrain Peon

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    header( 'Location: $url' ) ;
    ?>

    please give it a try
     
    biobrain, May 23, 2008 IP
    daryo likes this.
  5. daryo

    daryo Well-Known Member

    Messages:
    1,343
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Nope, not working, I asked a friend he gave me the code, and it's working :
    <?php
    $u=$_GET['url'];
    echo "
    <script>window.location='".$u."'</script>
    ";
    
    ?>
    PHP:
    Thanks anyways for your time :)
    rep added :)
     
    daryo, May 23, 2008 IP
  6. biobrain

    biobrain Peon

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Great it is fine
     
    biobrain, May 23, 2008 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <?php header("Location: $_GET['$url']"); ?>
    
    PHP:
    doesn't work because you have an array in the double quoted string: normal variables can be done like that, but not array items (reliably).

    
    <?php
    header( 'Location: $url' ) ;
    ?>
    
    PHP:
    won't work because you have a variable in a single quoted string: single quoted strings aren't parsed for variables.

    What you were looking for, really, is something like:
    
    <?php 
    header('Location: ' . $_GET['$url']); 
    ?>
    
    PHP:
    Hope that helps for the future...
     
    TwistMyArm, May 23, 2008 IP
    daryo likes this.
  8. daryo

    daryo Well-Known Member

    Messages:
    1,343
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    110
    #8
    Hmm your code won't work, showing me a blank page... thanks anyway...
     
    daryo, May 23, 2008 IP
  9. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #9
    God, got to say...NOOBS. Anyway:

    <?PHP
    die(header("location: ".$_GET['url']));
    ?>

    There...That will work, enjoy!
     
    NatalicWolf, May 23, 2008 IP
  10. Xtrm2Matt

    Xtrm2Matt Active Member

    Messages:
    129
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #10
    The reason this isn't working for you is because you're using a variable (or trying to) inside the GET.

    $_GET["$url"] will never work. It has to be $_GET["url"].
     
    Xtrm2Matt, May 23, 2008 IP
  11. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Ah crap, my bad... absolutely right guys. Sorry, just a little too much copy and pasting on my behalf...
     
    TwistMyArm, May 23, 2008 IP
  12. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #12
    <?php header('Location: '.$_GET['url']); die('Go to '.$_GET['url']); ?>
    PHP:
    Why was this thread SO long? :eek:, I would've made it a hyperlink but I'm lazy.
     
    Danltn, May 24, 2008 IP
  13. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #13
    You can use arrays inside double quotes ...

    
    <?php header("Location: {$_GET['url']}"); ?>
    
    PHP:
     
    krakjoe, May 24, 2008 IP