|
|
View previous topic :: View next topic |
Author |
Message |
imthenachoman
Posts: 2
|
Posted: Sat Aug 08, 2009 5:27 am Post subject: cURL + PHP + update watched/acquired shows |
|
|
I was hoping someone might be to help me with something.
I have figured out how to use cURL + PHP to login (and save my cookies) to myepisodes.com and then get data from different parts of the sites like the views.php part. What I can't figure out is why when I try to update watched/acquired data, it won't work.
Code: |
<?php
// initialize curl
$curl = curl_init();
// return data, don't print
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
// follow re-directs
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
// post data
$post = array(
'username' => 'imthenachoman',
'password' => 'password',
'u' => '',
'action' => 'Login',
);
//login page url
curl_setopt( $curl, CURLOPT_URL, 'http://www.myepisodes.com/login.php' );
// send post data
curl_setopt( $curl, CURLOPT_POST, 1 );
// post data
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $post ) );
// save to cookie file
curl_setopt( $curl, CURLOPT_COOKIEJAR, 'test' );
$result = curl_exec( $curl );
// confirm logged in
if( preg_match( '/imthenachoman/i', $result ) )
{
print 'logged in' . "\n";
}
else
{
print 'not logged in' . "\n";
}
curl_setopt( $curl, CURLOPT_URL, 'http://www.myepisodes.com/shows.php?type=manage' );
curl_setopt( $curl, CURLOPT_POST, 0 );
$result = curl_exec( $curl );
// this prints my shows list
print $result;
?>
|
Everything works fine up to this point.
Code: |
<?
// build new post string to update show id = 3156, season = 2, episode = 6
// not including A3156-2-6, or V3156-2-6 so it should mark this episode as un-acquired
$post = array(
'returnaddress' => '/views.php?',
'checkboxes' => '3156-2-6',
'action' => 'Save Status',
);
curl_setopt( $curl, CURLOPT_URL, 'http://myepisodes.com/views.php?type=save' );
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $post ) );
$result = curl_exec( $curl );
// but this prints the login page and it doesn't update show status as expected
print $result;
curl_close( $curl );
?>
|
The last part prints the login page. :'(
Any ideas anyone? |
|
Back to top |
|
|
IceMan Founder
Posts: 611 Location: Denmark
|
Posted: Tue Aug 11, 2009 7:55 pm Post subject: |
|
|
Has been moved. |
|
Back to top |
|
|
Fraak
Posts: 1
|
Posted: Wed Apr 07, 2010 6:58 pm Post subject: |
|
|
Try using the zend framework: Zend_Http_Client |
|
Back to top |
|
|
IceMan Founder
Posts: 611 Location: Denmark
|
Posted: Wed Apr 07, 2010 9:03 pm Post subject: |
|
|
If you get the login page again, then you are not preserving the cookie state correctly. |
|
Back to top |
|
|
aEnigma
Posts: 2
|
Posted: Mon May 10, 2010 4:24 pm Post subject: |
|
|
the problem is that the cookies are set during the header-location-change-response (status code 302 found)
most request-handler automatically get the linked webpage overwriting the cookies returned.
POST Request: login.php
Response: 302 Found myshows.php (+ login.php head -> cookies)
GET Request: myshows.php
Response: 200 (myshows.php head -> cookies & body data)[/quote] |
|
Back to top |
|
|
aciidb0mb3r
Posts: 5
|
|
Back to top |
|
|
nikkij
Posts: 1
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
Main design by MW. Refitted to board by Hostile.
|