-1

Say we have page 1:

<?php
$text=$_POST['text'];
echo 'You wrote "' . $text . '".';
?>

and page 2, which takes the user input, POSTs it to Page1, and gets the page (You wrote (input).). I'm not really sure about how to do this: googling (or better, stackoverflowing) a while, I found this question, which explains how to POST a variable to another page, but not how to get the code of the page. So, how to do both?

EDIT: An example of the actual situation. The user inputs the number 245. I get the number, pass it to this external page, get the page, retrieve the result (5*7*7) and show it. In italics you see the part I need.

Community
  • 1
  • 1
Giulio Muscarello
  • 1,312
  • 2
  • 12
  • 33

3 Answers3

2

I'd suggest using curl to POST the data, and then you'll probably need to parse the returned HTML.

Here's a blog post about how to use cURL to post. I'll leave using google to find an example of parsing HTML with PHP as an exercise for the reader . . .

Community
  • 1
  • 1
ernie
  • 6,356
  • 23
  • 28
  • Would you mind posting the proper code to POST the data and read the returned HTML (not parsed)? – Giulio Muscarello Nov 09 '12 at 18:24
  • 1
    [whathaveyoutried.com](http://whathaveyoutried.com)? If you run into specific issues, feel free to ask more questions, but SO is not the site to come to and expect complete code written for you. – ernie Nov 09 '12 at 18:27
0

page 1:

<form method="post" action="page2">
<input name="input" type="text"/>
<input type="submit" value="sendtopage2"/>
</form>

page 2:

<?php
$text=$_POST['input'];
echo 'You wrote "' . $text . '".';
?>
doniyor
  • 36,596
  • 57
  • 175
  • 260
  • You missed the point. I don't want the user to go on page2: the process happens entirely on my server, which sends a request to page2 and retrieves and parses the result. – Giulio Muscarello Nov 09 '12 at 18:23
0

Working example with cURL:

$function="sin(x)";
$var="x";
$url='http://www.numberempire.com/integralcalculator.php';
echo '<base href="' . $url . '">'; // Fixes broken relative links
$Curl_Session = curl_init($url);
curl_setopt ($Curl_Session, CURLOPT_POST, 1);
curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "function=$function&var=$var");
curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 0);
$content=curl_exec($Curl_Session);
curl_close ($Curl_Session);
Giulio Muscarello
  • 1,312
  • 2
  • 12
  • 33