Preg_match help needed

Discussion in 'PHP' started by adzeds, Feb 17, 2010.

  1. #1
    I am testing the http referrer to see if it is from another page on my site but it is throwing me a problem in that sometimes people search for my domain name, or links to my site contain my domain name.

    I am currently using :
    (preg_match ("/www.eaguingamp.co.uk/i", "$refurl"))

    I think I need to check that it also has the http:// How can I add that to this statement, It keeps throwing me an error!
     
    adzeds, Feb 17, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Do this...

    
    $referer = str_replace("www.", "", parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
    if(preg_match("/eaguingamp\.co\.uk/i", $referer)){
    
    //the visitor came from eaguingamp.co.uk, theirfore proceed...
    
    }
    PHP:
     
    danx10, Feb 17, 2010 IP
  3. adzeds

    adzeds Well-Known Member

    Messages:
    1,209
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #3
    Great work. Thank you!
     
    adzeds, Feb 17, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    if(stristr($_SERVER['HTTP_REFERER'], "eaguingamp.co.uk")){
    
    //the visitor came from eaguingamp.co.uk, theirfore proceed...
    
    }
    PHP:
    Don't know if your still following this thread, but forgot to mention this method, you might find it easier then using regular expressions :)
     
    danx10, Feb 19, 2010 IP
  5. nirajkum

    nirajkum Active Member

    Messages:
    815
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #5
    agree with danx as it would help you to get the visitor information
     
    nirajkum, Feb 19, 2010 IP