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.

HTTP_REFERER help please.

Discussion in 'PHP' started by inaga, Oct 7, 2008.

  1. #1
    what i want to do is:

    IF HTTP_REFERER = specific ip-address (coming from a specific website/server)

    do something

    else
    SEMrush
    do something else.

    what's the php code for this :D
    please help ^^.
     
    inaga, Oct 7, 2008 IP
    SEMrush
  2. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,109
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    could you use somthing like -
    <?php
    $url = $_SERVER['REQUEST_URI'];
    
    if($url=="IP?")
    {
    do this
    }
    
    ?>
    
    
    
    
    
    HTML:
    Untested, but you can play with it.
     
    Funk-woo10, Oct 7, 2008 IP
  3. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Funk-woo10,
    I think your example is not what the author told about :)

    inaga,
    You can try to do the follow:
    if ( $_SERVER['HTTP_REFERER'] == '127.0.0.1 or url here' ) {
    do smth;
    } else {
    do smth else;
    }
    PHP:
    I hope it will help you.
     
    GuitarFix, Oct 7, 2008 IP
  4. techcone

    techcone Banned

    Messages:
    206
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @above

    Small correction :

    if ( $_SERVER['REMOTE_ADDR'] == '127.0.0.1' ) {
    do smth;
    } else {
    do smth else;
    }
    PHP:
     
    techcone, Oct 7, 2008 IP
  5. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    techcone
    Hm.. maybe :)

    Maybe inaga meant by this:
    "specific ip-address (coming from a specific website/server)"
    an url which presented as an ip-address..?
     
    GuitarFix, Oct 7, 2008 IP
  6. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #6
    INAGA: clear the topic up,
    some think you want to block specific users with IP adress
    some think you want to block specific sites linking into your site


    i believe you want to achieve the latter, since REFERER is REFERER and not REMOTE_ADDR ;)


    so go with this code, if you want to block a specific site linking to you
    if(eregi("domain/ip/url-pattern-you-dont-want-to-link.to.you-here",$_SERVER[HTTP_REFERER])) { do-what-you-need-here; die; }
    Code (markup):
     
    happpy, Oct 7, 2008 IP
    inaga likes this.
  7. inaga

    inaga Active Member

    Messages:
    949
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #7
    inaga, Oct 7, 2008 IP
  8. inaga

    inaga Active Member

    Messages:
    949
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #8
    happy, your solution did it for me. thanks :) +rep.
     
    inaga, Oct 7, 2008 IP
  9. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #9
    If you want to extend it out perhaps this might work?

    
    
    $last_url = trim($_SERVER['HTTP_REFERER']);
    $parse_url = parse_url($last_url);
    $last_domain = $parse_url['host'];
    
    
    switch($last_domain)
    {
    
    case default:
    //If no match do this;
    break;
    case 'www.zomganime.com':
    //do something;
    break;
    }
    
    
    PHP:
     
    Sillysoft, Oct 7, 2008 IP
  10. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Sillysoft
    Why do you do "trim" to the "HTTP_REFERER"? I think the right way of that line is: $last_url = $_SERVER['HTTP_REFERER'];
     
    GuitarFix, Oct 9, 2008 IP
  11. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #11
    Well normally I have functions that would clean the variable, I just used trim to show that I try to clean it up first. But my normal function would trim it, strip any html etc etc. Never trust your data no matter what!

    Security should always be apart of any web application.
     
    Sillysoft, Oct 9, 2008 IP
  12. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Ah.. yes. Sure, I agree with you. You're absolutely right! Thanks for the explanation.
     
    GuitarFix, Oct 9, 2008 IP