Reputation: 59
I have a page with information on it, let's say
<p>username=test</p>
<p>password=test2</p>
i need to search through this page, find the value for username and the value for password, store them, probably in a variable. and carry them over onto a form on another page. like so:
Username: <input type="text" name="Username"><br />
Password: <input type="text" name="Password">
This second page i would very much like to not be on the same server. so using php POST is a tad out of the question, and i dont think you can carry variables between pages with javascript. Anyone have any ideas?
note:also, i have no access to the code on the other server, (the form) however i understand that js can be ran out of the url bar, so perhaps i could use this to fill in the textboxes.
Upvotes: 0
Views: 879
Reputation: 2194
Here you go, You Me:
You can use CURL with a GET-method request to read the HTML from the foreign web site. Then you can parse the HTML with PHP to isolate the form input controls and create a raw POST string. Following that you can use CURL POST to send the data to the "action" script. Your PHP script will need to act like a well-behaved web browser, accepting and returning cookies, following redirects, etc. When I have done this in the past I have found it to require a VERY long period for debugging, so build that into your plans. A much better way would be to contact the owners of that site and get an API.
All the best for the New year 2013, ~Ray
Upvotes: 1
Reputation: 53
You could use this in page1.php.
<form action="Page2.php" method="post">
<input type="text" name="Username" id="Username" /><br />
<input type="text" name="Password" id="Password" />
<input type="submit" name="submit" id="submit" value="Transfer Information" />
</form>
Page2.php contains:
<?php
$Username = $_POST[Username];
$Password = $_POST[Password];
?>
<p>Username="<?php echo $Username; ?>"</p>
<p>Password="<?php echo $Password; ?>"</p>
Upvotes: 0