+ Reply to Thread
Results 1 to 2 of 2

Thread: HTTP Post

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    12

    HTTP Post

    How do i create HTTP Requests from a php script ?
    Last edited by petervc; 11-12-2012 at 03:29 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    41
    In this Tutorial , you will be able to create HTTP posts using a php function i created.
    So here is the Snippet :
    Code:
    <?php
    
    post_data("http://www.bendasite.com/register.php","reg_username=anyusername&reg_email=anyemail%40gmail.com&reg_password=free123&reg_password2=free123&answer=7&submit=Create+user&regfrom=full");
    echo grap_page ("http://www.bendasite.com/register.php");
    //Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777
    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);    
    }
    
    ?>

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts