IPT Login via PHP

Status
Not open for further replies.

brazzO

Active Member
1,286
2009
211
0
I am trying to log in to IPT using my account via PHP.
So far i have got this:

PHP:
<?php
    
    login(http://iptorrents.com","*** my POST-DATA would be here*** ")
    echo grab_page("http://iptorrents.com");

    function login($url,$data){
        $fp = fopen("cookie.txt", "w");
        fclose($fp);
        $login = curl_init();
        curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
        curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
        curl_setopt($login, CURLOPT_TIMEOUT, 40000);
        curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($login, CURLOPT_URL, $url);
        curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($login, CURLOPT_POST, TRUE);
        curl_setopt($login, CURLOPT_POSTFIELDS, $data);
        ob_start();
        return curl_exec ($login);
        ob_end_clean();
        curl_close ($login);
        unset($login);    
    }                  
     
    function grab_page($site){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_TIMEOUT, 40);
        curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
        curl_setopt($ch, CURLOPT_URL, $site);
        ob_start();
        return curl_exec ($ch);
        ob_end_clean();
        curl_close ($ch);
    }
     
    function post_data($site,$data){
        $datapost = curl_init();
            $headers = array("Expect:");
        curl_setopt($datapost, CURLOPT_URL, $site);
            curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
        curl_setopt($datapost, CURLOPT_HEADER, TRUE);
            curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($datapost, CURLOPT_POST, TRUE);
        curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
            curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
        ob_start();
        return curl_exec ($datapost);
        ob_end_clean();
        curl_close ($datapost);
        unset($datapost);    
    }
     
    ?>

For somereason it doesn't want to log in?
Is there something i am missing out? I am fairly new at php so i'm probably just missing a few parts unless i need some more code to handle a different part as it's a torrent website.
Any help would be appreciated.

__________________
Added after 17 minutes:

never mind, got it working. now, to tackle the grabbing info part and outputting it :)

__________________
Added after 1 Day 7 Hours:

Got another problem, not sure if it will be an easy fix but here goes.
I have all the script connecting to IPT and logging in, only thing is when i am echoing the php code for the "get_data" function i am having a part at the bottom of my page that is asking me to log in.

here is the code:

PHP:
function get_data($url){
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);        
        curl_close($ch);
        return $data;
    }
    
    $returned_content = get_data('http://iptorrents.com/torrents');
    echo($returned_content);

i am logged in and getting all info but it is telling me to login at the very bottom and can't think why this would be.

__________________
Added after 20 Hours 51 minutes:

I am also having an error as follows:
PHP Warning: Missing argument 2 for get_data(), called in /home/pirouet/public_html/index.php on line 52 and defined in /home/pirouet/public_html/index.php on line 41

this is the lin 41:
PHP:
function get_data($url){

this is the line 52:
PHP:
$returned_content = get_data('http://iptorrents.com/torrents');
 
Last edited:
2 comments
Add the cookie file that you used to login to the get_data function

Code:
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
 
in your get_data function add the following lines:

curl_setopt($ch, CURLOPT_COOKIEJAR, "path-to-your-cookie-file");
curl_setopt($ch, CURLOPT_COOKIEFILE, "path-to-your-cookie-file");

Kindly make sure that wherever you are accessing user pages i.e. the pages which are accessible after a user logs in, you have to supply the cookie file.

As for the php warning for missing argument, I see that there you have declared the function using only one argument but still php is issuing this warning. This can be due to some caching or multiple declarations.
Kindly check if the changes have been properly saved and that there is no other function with the name get_data.
Rest seems fine.

In case you still aren't able to fix it, do let us know and we will help you out.

Thanks
 
Status
Not open for further replies.
Back
Top