Header Redirect -> Domain Referrer?

Discussion in 'PHP' started by brianj, Aug 26, 2009.

  1. #1
    Hi, i have some code like:

    
    <?php
    if($_GET['Domain']){
        header("Location: ".$_GET['Domain']."");
    }
    ?>
    PHP:
    I'm trying to make a redirect based on the referrer source:
    (Example: ht*p://myblog.com/index.php?domain=google.com


    Any ideas for this?
     
    brianj, Aug 26, 2009 IP
  2. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    if($_GET['Domain'])){
    $d = "http://".$_GET['Domain'];
    header("Location: $d");
    }
    ?>
    
    PHP:
    However, if the URL actually is ht*p://myblog.com/index.php?domain=google.com, your $_GET['Domain'] needs to be $_GET['domain']
     
    SHOwnsYou, Aug 26, 2009 IP
  3. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Hey thanks, makes sense.. but i also need to get the referrer first, how to put that in?
     
    brianj, Aug 26, 2009 IP
  4. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #4
    What exactly u want to do with the referer . you can get the refer using

    SERVER["HTTP_referer"];
     
    Bohra, Aug 26, 2009 IP
  5. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Hi, i need to strap out the domain (domain.com) out of the referer and then redirect to a separate page, like index.php?domain=domain.com

    
    <? 
    $referer = SERVER['HTTP_referer'];
    $domain = $referer;
    
    if($_GET['domain'])){
    $d = "http://".$_GET['domain'];
    header("Location: $d");
    }
    
    ?>
    
    PHP:

    ??
     
    brianj, Aug 26, 2009 IP
  6. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you dont have the referer already, you would want something more like this:

    
    <?php
    $ref = $_SERVER['HTTP_REFERER'];
    header("Location: $ref");
    }
    ?>
    
    PHP:
     
    SHOwnsYou, Aug 26, 2009 IP
  7. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Yes thanks, but not the full referer URL.. instead i wan't to redirect to myblog.com/domain=domain.com
     
    brianj, Aug 26, 2009 IP
  8. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Depending on what you plan to do with the project, this can be really simple or kinda difficult.

    What is the purpose of redirecting them to index.php?domain=domain.com ??
     
    SHOwnsYou, Aug 26, 2009 IP