Page 1 of 1
access code in a webpage to modify it
Posted: Sun Oct 05, 2008 2:57 pm
by Lorna
Hello,
I am using a webpage which calculates for me some values, but I have a loooong list of values and I want this to be done non-interactively (through a loop ). The problem is that the webpage is not mine and I do not know how to submit many requests without actually having to press the submit button multiple times. Please help, I am tired of pressing this button and I'm not even close to finishing 1/10 of my data.
Thanks in advance
Re: access code in a webpage to modify it
Posted: Sun Oct 05, 2008 3:05 pm
by Ziq
You can use
fsockopen() or
cURL library.
Re: access code in a webpage to modify it
Posted: Sun Oct 05, 2008 3:27 pm
by Ziq
For example if you want to send POST-data:
Code: Select all
<?php
$hostname = "www.somehost.com";
$path = "/print.php";
$line = "";
$fp = fsockopen($hostname, 80, $errno, $errstr, 30);
if (!$fp) echo "$errstr ($errno)<br />\n";
else
{
// POST-data
$data =
"name=".urlencode("Dmitriy")."&pass=".urlencode("my&pass")."\r\n\r\n";
// HTTP-header
$headers = "POST $path HTTP/1.1\r\n";
$headers .= "Host: $hostname\r\n";
$headers .= "Content-type: application/x-www-form-urlencoded\r\n";
$headers .= "Content-Length: ".strlen($data)."\r\n";
$headers .= "Connection: Close\r\n\r\n";
// send
fwrite($fp, $headers.$data);
// get
while (!feof($fp))
{
$line .= fgets($fp, 1024);
}
fclose($fp);
}
echo $line;
?>
for the GET data you can see a example in the official documentation.
Re: access code in a webpage to modify it
Posted: Sun Oct 05, 2008 5:43 pm
by josh
I'd recommend reading the RFCs for the HTTP protocol as well, yeah there's libraries like Curl ( and ultimately thats what you'll want to use ), but understanding what it is you're trying to do is pretty essential to understanding and ultimately solving the problem. Yeah http may seem self explanatory but it helps to know how post data is formatted and handled, etc..