I made a script for a site,
i can login,and make some acties...but if i refresh the
script like 5 minutes later,i have to login again...
Snoopy doesn't hold the cookie...
this is my script...
<?
include "Snoopy.class.php";
$snoopy = new Snoopy;
# INLOGGEN.
$submit_url
= "http://www.bootleggers.us/checkuser.php";
$submit_vars["username"] = "username";
$submit_vars["password"] = "password";
$snoopy->submit($submit_url,$submit_vars);
# CRIMEN RIPPEN.
$submit_url
= "http://www.bootleggers.us/crime.php";
$random_crime = rand(1,1);
$submit_vars["crime"] = $random_crime;
$snoopy->submit($submit_url,$submit_vars);
This works perfectly,but i dont want to login every 5
minutes...
what am i doing wrong?
Logged In: NO
Snoopy doesn't seem to have any code for holding cookies
sent to it from the webserver. :(
Logged In: YES
user_id=1040113
You need to set the cookies either on your workstation, or
inside snoopy before your next fetch/submit ... vis
=============================
$snoop->fetch($submit_url);
for ( $x=0; $x<count($snoop->headers); $x++ ) {
if (strstr($snoop->headers[$x], 'Set-cookie: ')) {
$cookie_content = substr($snoop->headers[$x],12));
$cookie_array = parse_cookie();
for ($y=0; $y<count($cookie_array); $y++) {
$snoop->cookies[trim($cookie_array[$y]["key"]) =
trim($cookie_array[$y]["value"]);
}
}
}
$submit_url="something else";
$snoopy->fetch($submit_url);
I'll not bother spelling out the parse_cookie function.
After all, if you don't know how something works, you
shouldn't be using it, and parsing a cookie is pretty simple.
If you just want snoopy to log in for yuou, and then carry
on using the normal access methods to the pages afterwards,
you need to save the complete cookie locally. To do that you
can make a more extensive parse_cookie function (one which
keeps path and expiry time info) and then use setcookie() to
set them locally.
However, remember that snoopy is running on the server, not
locally, so some cookies (those which use ip address as an
encoding seed) will fail to ework if you get them with
snoopy and set them locally.
Hope that helped ...
Kevin Salt
Technical Webmaster - European Space Agency
ksalt at arr ess ess dee (those were letters) dot esa dot int
Logged In: NO
[quote]I'll not bother spelling out the parse_cookie function.
After all, if you don't know how something works, you
shouldn't be using it, and parsing a cookie is pretty simple.
[/quote]
grr, i like things handed to me!
Well i took ur word that it was simple (btw one typo in ur
code), and spent a few minutes figuring it out, hence the new
complete code, which I am using.
for ($i=0; $i<count($snoopy->headers); $i++) {
if (strstr($snoopy->headers[$i], 'Set-Cookie: ')) {
$cookie_content = substr($snoopy->headers[$i],12);
$cookie_content = explode(";",
$cookie_content);
foreach($cookie_content AS $val){
$cookie_array=explode("=", $val);
$snoopy->cookies[trim
($cookie_array[0])]=trim($cookie_array[1]);
}
}
}
Logged In: NO
[quote]I'll not bother spelling out the parse_cookie function.
After all, if you don't know how something works, you
shouldn't be using it, and parsing a cookie is pretty simple.
[/quote]
grr, i like things handed to me!
Well i took ur word that it was simple (btw one typo in ur
code), and spent a few minutes figuring it out, hence the new
complete code, which I am using.
for ($i=0; $i<count($snoopy->headers); $i++) {
if (strstr($snoopy->headers[$i], 'Set-Cookie: ')) {
$cookie_content = substr($snoopy->headers[$i],12);
$cookie_content = explode(";",
$cookie_content);
foreach($cookie_content AS $val){
$cookie_array=explode("=", $val);
$snoopy->cookies[trim
($cookie_array[0])]=trim($cookie_array[1]);
}
}
}