-2

I want to fetch content from an EXTERNAL webpage. Meaning it is not my webpage and I do not have the details of the exact fields sent in POST (can I see hidden fields if I check source code?) or the response returned. For ex, I have http://example.com which takes userid(through a text box) as input and when pressed submit, it displays details of entered userid in another page (http://example.com/details.php). I want to fetch contents from this PHP page. How can I do this?

Rachit
  • 5,021
  • 2
  • 14
  • 9
  • 1
    You can try with JSoup or Selenium. I'm voting to close this question as too broad. – Alessandro Da Rugna Dec 27 '15 at 09:57
  • How do you want to fetch those contents? The fact that that page was build using PHP is irrelevant. I find it hard to understand what exactly you need. – GolezTrol Dec 27 '15 at 09:59
  • There are plenty of explanations and answers available on Google. Do a quick search and within few links you'll have your answer. – Rajdeep Paul Dec 27 '15 at 10:07
  • You are getting downvoted because this got answered like ten minutes ago. it gets asked all the time. http://stackoverflow.com/a/34479191/2218253 – wuno Dec 27 '15 at 10:08

2 Answers2

2

Check the form element in the HTML page you mentioned:

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

A form describes an HTTP request, e.g. it describes the request your browser will send to the server when you submit the form. In this case, an HTTP request with the HTTP method POST will be created. The POST body will contain one parameter called rid with the value of whatever you entered in the form.

When submitting the form from my browser, it creates this request:

POST /vitavi.php HTTP/1.1
Host: results.vtu.ac.in
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://results.vtu.ac.in/
Connection: keep-alive

with the POST body containing:

rid=42&submit=SUBMIT

As long as there is no CSRF protection on the web page (and there isn't), you can create this request from wherever you like, including PHP. All you need is some tool or function to create an HTTP request with, e.g. file_get_contents, curl or a lib like Guzzle, etc. Since you want to parse the results afterwards, I'd suggest to do it with DOM directly.

For further reference, check

Community
  • 1
  • 1
Gordon
  • 296,205
  • 68
  • 508
  • 534
0

You can do like this:

After submit form use header location for redirect on the details page with id parameter.

<?php
header('Location: http://example.com/details.php?id='.$userid);
?>

Now in the details.php file you can use below code to get id and fetch record from database.

<?php
$id = $_REQUEST['id'];

$sql = "SELECT * FROM table_name WHERE id = '".$id."'";

$result = mysql_query(); if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit; }

$row = mysql_fetch_row($result);

echo $row[0]; // 42 echo $row[1]; // the email value ... .. etc
?>

Let me know if you needed anymore help! Thanks

Vinod Patidar
  • 695
  • 4
  • 17