Want to retrieve academic result data from the other site to my site [closed]
I am creating a academic/community site in Joomla . One of my site requirement is to obtain the result from the official college site . I will be creating a module on my site which will have college id as input and on submission it will show the result obtained from the official website .
I am finding it difficult to pass the data from one site to other . The official website is using Post method for college id input .
Please help me with detailed appr开发者_运维知识库oach with programming code sample . It will be highly appreciated . Thanks.
You will need something like PHP CURL for your problem. Your code could be something like:
<?php
$url = "http://www.collegesite.com";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "collegid=40"); // add POST fields
$result = curl_exec($ch); // run the whole process
curl_close($ch);
echo $result;
?>
Then you can use regex to get whatever data you want from $result. You may want to read the net up a bit about CURL.
精彩评论