Managing cookies with PHP

Discussion in 'PHP' started by Ithilnet, Jun 7, 2007.

  1. #1
    This maybe a newbie question.

    Basically I need to know how to use php to login to a site and manage the session. Usually a site will set cookies for this so I need to know how to manage those cookies.
    I'm sure its simple i just dont know how to do it yet and coulnd't find the right infos online.

    Thanks
     
    Ithilnet, Jun 7, 2007 IP
  2. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You don't need to deal with cookies if you want to use a session, the PHP $_SESSION takes care of everything for you.

    
    //page1.php
    
    session_start();  // start using a session
    
    $_SESSION['myVar'] = 'Hello World!';  // set something in your session
    
    PHP:
    
    //page2.php
    
    session_start();  // start using a session
    
    if(isset($_SESSION['myVar'])){
       print $_SESSION['myVar'];  // will print your Hello World!
    }else{
       print 'Ohh boy, I don\'t see my session variable';
    }
    
    
    PHP:
    Simple as apple pie.

    Basically, on any page you want to use session data you need to first start the session by using session_start(), after that you simply set/get your session data from the $_SESSION array.
     
    mrmonster, Jun 7, 2007 IP
  3. Ithilnet

    Ithilnet Peon

    Messages:
    167
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry my question wasn't clear, i need to use PHP to log into a REMOTE site (not managed by me) to automate some tasks.
     
    Ithilnet, Jun 7, 2007 IP
  4. Ithilnet

    Ithilnet Peon

    Messages:
    167
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Anyone to point me in the right direction?
     
    Ithilnet, Jun 8, 2007 IP
  5. SeLfkiLL

    SeLfkiLL Active Member

    Messages:
    85
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    50
    #5
    SeLfkiLL, Jun 8, 2007 IP