Need some PHP help with cookies!

Discussion in 'PHP' started by Seqqa, Sep 17, 2008.

  1. #1
    Hey

    I need a PHP script that would load in a JavaScript call up for example below...

    <script type="text/javascript" src="http://example.com/script.php"></script>

    I need PHP that looks for a cookie and if its not found loads a .js file?

    Anyone know how this could be done?

    +rep for anyone with a script!
     
    Seqqa, Sep 17, 2008 IP
  2. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Make the cookies with:
    
    setcookie('nojs','blah',time()+86400); //expires in 24 hours
    
    PHP:
    check if it exists:
    
    if(isset($_COOKIE[nojs])){
     echo 'It exists!';
    }
    else{
     //execute js
    }
    
    PHP:
    hope it helps :)
     
    lui2603, Sep 17, 2008 IP
    Seqqa likes this.
  3. Seqqa

    Seqqa Well-Known Member

    Messages:
    3,695
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    115
    #3
    if(isset($_COOKIE[nojs])){ echo 'It exists!';}else{ //execute js}
    PHP:
    How would I put that together to work? Where does the JS file go?
     
    Seqqa, Sep 18, 2008 IP
  4. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    js file goes here - //execute js

    replace //execute js with JS !
     
    Funk-woo10, Sep 18, 2008 IP
    Seqqa likes this.