How to Fetch Result from another website via help of php

Today every developer wants to  search results (from another website) show in our website webpage.
like as:

  • india results
  • rtu portal
  • many results sites


so today we learn how to fetch data from another website. for this purpose we use php curl lib function.
php allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.


In this tutorial i want to show you how you get exam results on your website from university website.

For Example:

we want to fetch result from vtu.ac.in (Visvesvaraya Technological University).
the result page of this website is http://results.vtu.ac.in/vitavi.php
So here the own code to fetch result from university server

<?php
echo '<form action="' . $_SERVER[PHP_SELF] . '" method="post">
<input type="text" name="rid">
<input type="submit" name="submit" value="submit">
</form>';
if(isset($_POST['submit'])&&(!empty($_POST['rid'])))
{
    $location = 'http://results.vtu.ac.in/vitavi.php';

    $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $location );

    $post_array = array(
        "rid" => $_POST['rid'],
        "submit" => "submit"
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 
    $response = curl_exec($ch);

    $start = '<TD width="513">';
    $end = '<br>';

    $response = strstr($response, $start);
    $end = stripos($response, $end);
    $response = substr($response, strlen($start), $end - strlen($start));

    echo $response."<br/>";
}  


To Download the source code:

To Live Demo:


Linux Installation Guide