hi
i'm new to php but i tried to make my own edu website but i'm facing lot of problem to fetch the result using php
external site is about one of the Engineering university where 10k students result will be displayed by this website bcoz of this its server will be busy.so i tried to fetch the result from it.
coming to reqirement
when the students enter their usn no(eg:1db11cs001) when user hit submit button it must fetch result from external website(eg:http://results.vtu.ac.in/vitavi.php) and it must display result on my website
so plz help me by giving complete code
for more details and code
plz follow the link
http://stackoverflow.com/questions/13899643/to-fetch-the-form-results-from-an-external-website-on-the-same-page
coming to problem topic
when the student enter thier usn no/roll no(eg:1db13cs005) its just showing the student name but i need the complete result copy to be displayed on my website

Recommended Answers

All 19 Replies

Member Avatar for diafol

First of all, make sure you're not falling foul of the university/college by doing this. If it's OK, then I'm assuming that you need to use cURL to scrape the page unless they have an API which could allow you to once again use cURL or file_get_contents or even use js to get json data.

<form name="new" action="vitavi.php" method="POST">
 <p>Enter the University Seat No: <input type="TEXT" name="rid" size="20" maxlength="50"><br><br><br><br>
 <input type="SUBMIT" name="submit" value="SUBMIT" align="center"><br></p>
<form>

So it seems that if you were to use cURL for instance, you'd want to pass the POST "new", "rid" and "submit"

You may wonder about the need to pass "submit", but it may be part of validating whether the form had been submitted, e.g.

if(isset($_POST['submit']))

So you'd set the cURL to look at http://results.vtu.ac.in/vitavi.php

i'm gettin 404 error to the below code can u solve this problem

<?php

echo '<form name="new" action="vitavi.php" method="POST">
 <p>Enter the University Seat No: <input type="TEXT" name="rid" size="20" maxlength="50"><br><br><br><br>
 <input type="SUBMIT" name="submit" value="SUBMIT" align="center"><br></p>
<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/>";
}  

?>

@diafol
i've tried my level to clear my error but i couldn't fix it so help me out

but to the above code it is fetching student name but i need to fetch complete exam result sheet from external website
plz can anyone solve this

Member Avatar for diafol

The html is wrong in my original - the close form tag should be:

</form>

Also the action shouldn't be "vitavi.php" unless you have a page called that on your site.

Member Avatar for diafol
if(isset($_POST['submit']) && isset($_POST['rid']) && !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/>";
}  
?>

<html>
<form name="new" method="POST">
 <p>Enter the University Seat No: <input type="TEXT" name="rid" size="20" maxlength="50"><br><br><br><br>
 <input type="SUBMIT" name="submit" value="SUBMIT" align="center"><br></p>
</form>
</html>

Works for me (name and id)

@diafol
for the above code its just accessing only student name and id but i need to fetch complete result as shown below 7e6294b1d2f0140535ac6b2835c96c52

i just test above code after response print it working.
$response = curl_exec($ch);
print_r($response);
exit;

Member Avatar for diafol

The reason you only get the name is because you place a stop at '<br>'. Unfortunately the underlying html for the table is a total mess. Many nested tables. A way around this may be to use an xmlparser, but in order to use these, the xml/html needs to be well formed and I'm not sure this page has well-formed html. If you can find any hooks e.g. classes or attributes then setting multiple start and end points may be possible.

THis works to output the table...

$response = curl_exec($ch);

//change this to whatever...
$extract = array("start" =>'<TD width="513">', "end"=>'<b>REGISTRAR(EVALUATION)</b>');

$start = stripos($response, $extract['start']);
$end = stripos($response, $extract['end']);
$response = substr($response, $start, $end);

echo $response."<br/>";

BUT, as I mentioned, the html will not be well formed, you'll probablt need to add various open and close tags to the response to make it well formed on your page.

@diafol
personally i thank u.for giving code its perfectly working.

@mangel_murti
thank u for solving problem .its working fine

when they announce the result in VTU can i store all students exam result in my database from external site(vtu) before/while displaying students result

Member Avatar for diafol

when they announce the result in VTU can i store all students exam result in my database from external site(vtu) before/while displaying students result

Ensure that you have permission to do this. I assume that this is confidential information. Have students given you permission to access their data? Is the uni/college aware that you are scraping their site for data? These should be concerns that you should address. Pleading ignorance will not help in the event of complaints being made. As the college/uni are responsible for keeping students' results saf, so will you (if you get permission in the first place, that is).

@diafol
i'm nt sure of storing result but in our uni website the previous year results are not display but in other website like Click Here.com,Click Here... they r able to show result from this i think they r storing results in their database

Member Avatar for diafol

OK, well that's an issue for you. But be aware just because somnebody else if ripping off data, doesn't mean it's open season for everybody else. Equally, that site may have an agreement with the uni.

Storing data in a db may be a bit dodgy - especially as you may at a later date, just scrape, store and deliver the stored data. That would not then take into account any ammendments to the original data.

What would be really useful is if the uni had an api that allowed "key holders" to access the data.

@diafol
for more info abt external site(vtu) follow this link Click Here
without storing result in my db can i make rank list according to class student marks (ascending order)
firstly i will give info of our id(1db12cs005
in this 1 is indicated for bangalore region,"db" stands for college code,"12" stands for which sem we r studing right now,"cs" stands for computer science course,"005" is our reg no)
i want to make class rank for eg for cs course itself
this type of detail i hv seen in vtualerts so can u help me out

Member Avatar for diafol

If you store data, you can output it any way you want, BUT are you allowed to do so?

You could split the id with preg_* functions:

integer|short alpha (2 chars?)|integer|short alpha (2 chars?)|intger

OK, I think I've made it quite clear by now that you need to check if you need permission to store this data. Personally I would not store this data without contacting the uni. As a student, I would be very concerned that anybody could access my private data. For instance, do I want you to rip off my results and then rank them compared to everybody else? I don't think I would.

ok
can i give a download link of result to a student below their result sheet

Member Avatar for diafol

That's up to you mate. But don't ask me, ask the uni. Good luck with it, over and out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.