access code in a webpage to modify it

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Lorna
Forum Newbie
Posts: 1
Joined: Sun Oct 05, 2008 2:52 pm

access code in a webpage to modify it

Post 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
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: access code in a webpage to modify it

Post by Ziq »

You can use fsockopen() or cURL library.
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: access code in a webpage to modify it

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: access code in a webpage to modify it

Post 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..
Post Reply