1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to add values to a PHP redirect?

Discussion in 'PHP' started by Seqqa, Dec 3, 2008.

  1. #1
    I have this code below I guess you can work out what i'm trying to do basically I'm trying to add a value to a URL before it redirects.

    <?php
      $id = $_GET['id'];
    
      header("Location:"http://www.example.com/'.$id'/");
      exit;
    ?>
    PHP:
    I'm not sure if I'm on the right track or not? +rep for any help!
    SEMrush
     
    Seqqa, Dec 3, 2008 IP
    SEMrush
  2. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    right idea... I made a post about this here: 301 Redirect

    That should pretty much point you in the right direction.
     
    cgo85, Dec 3, 2008 IP
    Seqqa likes this.
  3. pharmboy

    pharmboy Member

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Yes, you're on the right track. Something like this should work:

    
    <?php
      $id = $_GET['id'];
    
      header("Location: http://www.example.com/" . $id . "/");
      exit;
    ?>
    
    PHP:
    Actually I think header("Location: http://www.example.com/$id/"); would work as well, though I've never bothered to try it.
     
    pharmboy, Dec 3, 2008 IP
    Seqqa likes this.
  4. xd2

    xd2 Peon

    Messages:
    694
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You have it right but you have to many " in the script this line

    header("Location:"http://www.example.com/'.$id'/");
    Code (markup):
    should be

    header("Location: http://www.example.com/".$id."/");
    Code (markup):
     
    xd2, Dec 3, 2008 IP
    Seqqa likes this.
  5. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?php
    $id = $_GET['id'];
    header( "HTTP/1.1 301 Moved Permanently" ); //the original page was http://www.coyol.net/seo.php
    header( "Location: http://www.example.com/$id/" );
    exit();
    ?>
    
    PHP:
     
    cgo85, Dec 3, 2008 IP
  6. wmtips

    wmtips Well-Known Member

    Messages:
    590
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Shorter way to do 301 (or any other HTTP header):

    <?php
    $id = $_GET['id'];
    header( "Location: http://www.example.com/$id/", true, 301);
    exit();
    ?>
    PHP:
     
    wmtips, Dec 3, 2008 IP
    Seqqa likes this.