Check URL before executing code

Discussion in 'JavaScript' started by payoutwindow, Feb 20, 2009.

  1. #1
    Hey people .. I need a little help.

    I have some code like this

    <script src="http://www.abcdef.com/mbvcn.php?sfs=6123761283&" language="JavaScript" type="text/javascript"></script><noscript><link href="http://asdsda.com/adsad" type="text/css" rel="stylesheet"/></noscript>
    Code (markup):
    however I want to only execute this code if the url is mydoain.com/folder/

    Can some please put up code on how to do this. The site is php based, so even that would be okay.
     
    payoutwindow, Feb 20, 2009 IP
  2. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    in your .php being called, $_SERVER['HTTP_REFERER'] is what you need to check on, with a strpos() or a preg_match..

    http://www.php.net/preg_match

    RTFM buddy
     
    rene7705, Feb 20, 2009 IP
  3. payoutwindow

    payoutwindow Well-Known Member

    Messages:
    788
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Okay ... pointed me in the right directions there.

    This is what I have so far ... however the javascript is still not working!!!

    Any more help??

    
    <?php
    $ref = $_SERVER["PHP_SELF"];
    $ref = substr($ref, 0, 6);
    //echo $ref;
    if ( $ref == '/2010/' )
    {
    //record visit
    echo "<script src="http://www.xxxxx.com/qwwwrwqw.php?pub=1324239&wwewq=adsas%sj21" language="JavaScript" type="text/javascript"></script><noscript><link href="http://adsasddaas.com/nojava.css" type="text/css" rel="stylesheet"/></noscript>";
    //echo $ref;
    }
    ?>
    
    PHP:
    Error
    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/xxxxx/public_html/2010/test.php on line 8
    Code (markup):
     
    payoutwindow, Feb 21, 2009 IP