+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP- maintaining cookies within script

  1. #1
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    PHP- maintaining cookies within script

    Hi. I'm trying to use a script to login to a website with different accounts and let me know if each has any PMs.
    For example:
    PHP Code:
    require_once('usernames.inc'); //contains $names=array(array('account1','pass1')) etc
    {// functions
    function login($name,$pass)
      {
      
    $name str_replace(' ','_',$name);
      
    file("http://awebsite.com?logon=1&user=$name&password=$pass");
      }
    }


    foreach (
    $names as $key => $value)
    {
    login($value[0],$value[1]);
    check_pm(); //sees if a PM is waiting to be read.
     
    }
    // outputs list of accounts with PMs. 
    However, my issue is that the login function DOES login, but the cookie is not saved. If I use an account to look at the ones I listed, it shows that the accounts have all signed in. If however I login and then immediately print_r(file($pageview)) the result shown shows "please log in".

    Is there an environment setting I need to change? Or should I be trying something other than file?
    NOTE: currently trying this on my localhost, so changing PHP.ini etc or even Apache configuration is not a problem.

    EDIT: Just to clarify, I'm not actually displaying any pages (except for bug testing). All the work is done in the same single script. Just need the script to remember the cookie so it can view the page whilst logged in.

    thx in advance
    Last edited by Scoochi2; 10-17-2011 at 06:02 PM.

  2. #2
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: PHP- maintaining cookies within script

    You'd need to use the CURL library to maintain cookies (rather then file()), and will probably have to use CURLOPT_COOKIESESSION to blow away a logged-in session between logins.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  3. #3
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP- maintaining cookies within script

    thanks essellar, guess I'll be downloading cURL tomorrow
    Last edited by Scoochi2; 10-17-2011 at 08:16 PM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

+ Reply to Thread

Similar Threads

  1. Teamspeak 3 - running and maintaining
    By allofus in forum VPS Talk
    Replies: 2
    Last Post: 04-15-2010, 05:54 PM
  2. Cookies
    By Steeevoe in forum Programming Help
    Replies: 2
    Last Post: 02-19-2009, 02:50 PM
  3. Too Many Cookies!
    By Coldfirezz in forum Programming Help
    Replies: 8
    Last Post: 11-22-2008, 06:46 AM
  4. Replies: 1
    Last Post: 10-19-2007, 07:02 PM
  5. cookies ¿?
    By jptosso in forum Soporte
    Replies: 3
    Last Post: 10-18-2007, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers