PHP- maintaining cookies within script

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
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:
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:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
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.
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
thanks essellar, guess I'll be downloading cURL tomorrow :)
 
Last edited:
Top