PHP Help

Discussion in 'Web Design & Coding' started by system32, Mar 7, 2003.

  1. system32

    system32 Guest

    I'm just getting started with PHP and was wondering how I would write a script to do the following...

    Read a cookie and if it states that a user is logged in then change the source of "image1".
     
  2. system32

    system32 Guest

    if that description is too vague just let me know...
     
  3. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Not sure I follow here... If you mean that image1 is allready displayed and you want to change it you a bit up the wrong tree. PHP doesn't run once the page is displayed.

    Anyway:
    PHP:
    if($HTTP_COOKIE_VARS["cookie_name"] == "text in cookie"){
        
    // Change the source (??)
    }
    else{
        
    // Not logged in
    }
     
  4. system32

    system32 Guest

    Zedric, I mean when the page is loading, I want the script to check for the cookie and determine which image will be displayed.

    It would be okay if once it reads the cookie to refresh the page too, if that's at all possible.
     
  5. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Like this then:

    PHP:
    if($HTTP_COOKIE_VARS["cookie_name"] == "text in cookie"){
        echo 
    "<IMG SRC='user_logged_in.jpg'>";
    }
    else{
        echo 
    "<IMG SRC='user_not_logged_in.jpg'>";
    }
     
  6. system32

    system32 Guest

    My hero. lol thanks man