HTTPS CURL login-403 Forbidden Error

Discussion in 'PHP' started by afimafis, Feb 5, 2012.

  1. #1
    Hi all,


    whenever i try code below in my remote hosting account.i get this error. i need your help thanks

    ERROR is :"You are being redirected.1403 Forbidden: The server understood the request, but is refusing to fulfill it."



    <?php


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://twitter.com/sessions?phx=1');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'session%5Busername_or_email%5D=XXXXX%5Bpassword%5D=YYYYY&scribe_log=%5B%22%7B%5C%22event_name%5C%22%3A%5C%22web%3Afront%3Alogin_callout%3Aform%3Alogin_click%5C%22%2C%5C%22noob_level%5C%22%3Anull%2C%5C%22internal_referer%5C%22%3Anull%2C%5C%22user_id%5C%22%3A0%2C%5C%22page%5C%22%3A%5C%22front%5C%22%2C%5C%22_category_%5C%22%3A%5C%22client_event%5C%22%2C%5C%22ts%5C%22%3A1327946553535%7D%22%5D&redirect_after_login=')
    ;//'ctl00$ctl00$ctl00$MainContent$MainContent$MainContent$LoginForm$emailAddress=xxxx@xxxx.com&ctl00$ctl00$ctl00$MainContent$MainContent$MainContent$LoginForm$password=xxxx');
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    $test = curl_exec($ch);
    print_r($test);

    class Curl {


    public $cookieJar = "";


    // Make sure the cookies.txt file is read/write permissions
    public function __construct($cookieJarFile = 'cookies.txt') {
    $this->cookieJar = $cookieJarFile;
    }


    function setup() {
    $header = array();
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] = "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // browsers keep this blank.


    curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7');
    curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieJar);
    curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookieJar);
    curl_setopt($this->curl, CURLOPT_AUTOREFERER, true);
    curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
    }


    function get($url) {
    $this->curl = curl_init($url);
    $this->setup();


    return $this->request();
    }


    function getAll($reg, $str) {
    preg_match_all($reg, $str, $matches);
    return $matches[1];
    }


    function postForm($url, $fields, $referer = '') {
    $this->curl = curl_init($url);
    $this->setup();
    curl_setopt($this->curl, CURLOPT_URL, $url);
    curl_setopt($this->curl, CURLOPT_POST, 1);
    curl_setopt($this->curl, CURLOPT_REFERER, $referer);
    curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
    return $this->request();
    }


    function getInfo($info) {
    $info = ($info == 'lasturl') ? curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL) : curl_getinfo($this->curl, $info);
    return $info;
    }


    function request() {
    return curl_exec($this->curl);
    }
    }

    //include('/curl.php'); // This path would change to where you store the file
    $curl = new Curl();


    $url = "https://twitter.com/sessions?phx=1";
    $fields = "session%5Busername_or_email%5D=XXXXX&session%5Bpassword%5D=YYYYY&scribe_log=%5B%22%7B%5C%22event_name%5C%22%3A%5C%22web%3Afront%3Alogin_callout%3Aform%3Alogin_click%5C%22%2C%5C%22noob_level%5C%22%3Anull%2C%5C%22internal_referer%5C%22%3Anull%2C%5C%22user_id%5C%22%3A0%2C%5C%22page%5C%22%3A%5C%22front%5C%22%2C%5C%22_category_%5C%22%3A%5C%22client_event%5C%22%2C%5C%22ts%5C%22%3A1327946553535%7D%22%5D&redirect_after_login=";


    // Calling URL
    $referer = "https://twitter.com/";


    $html = $curl->postForm($url, $fields, $referer);


    echo $html;
    ?>
     
    Solved! View solution.
    afimafis, Feb 5, 2012 IP
  2. #2
    is it a kind of twitter client?
     
    qwerty12, Feb 6, 2012 IP
  3. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    afimafis, Feb 6, 2012 IP