PHP Script Help, PLEASE

Discussion in 'General Programming Chat' started by bert6911, Jan 16, 2010.

  1. bert6911

    bert6911 Registered Member

    Joined:
    Apr 23, 2007
    Messages:
    82
    Likes Received:
    22
    Location:
    RiderVille
    Ok, I know the answer to this is going to be simple, BUT I have never had to use this type of check before and I don't know the keys/values to use.
    So I want to check if a referer to my site CONTAINS a certain variable that I will assign and if it does, do something different than if it doesnt.

    Example:

    If the referer to my site contains google.com I want to be able to just set the contains to check for "google" and then go elsewhere if it does contain that.

    How do I check if a referer just CONTAINS something, instead of having to put in the entire url.

    Hopefully that makes sense.

    Thanks in Advance!
     
  2. Petrel

    Petrel Registered Member

    Joined:
    Aug 27, 2009
    Messages:
    62
    Likes Received:
    10
    Attempt to find the position of 'google.com' by using function strpos.

    Code:
    $pos = strpos($string, 'google.com');
    
    if ( $pos === false )
    {
    print "Not found";
    }
    
    if ( $pos !== false )
    {
    print "Found";
    }
    
    Yes, we are using and extra =
     
    • Thanks Thanks x 1
  3. bert6911

    bert6911 Registered Member

    Joined:
    Apr 23, 2007
    Messages:
    82
    Likes Received:
    22
    Location:
    RiderVille
    Got it. Had to modify the above code a bit for my script. But it works. THANK YOU!
     
    Last edited: Jan 16, 2010
  4. nerdmoney

    nerdmoney Junior Member

    Joined:
    Feb 24, 2008
    Messages:
    135
    Likes Received:
    37
    Occupation:
    web nerd
    this is what i use:

    HTML:
    if 
    (substr((trim($_SERVER['HTTP_REFERER'])),0,22)=="http://www.google.com/")
    {
    do this
    }
    
    replace the 22 with the number of characters, so http://google would be 13
     
    • Thanks Thanks x 1