Solved

PHP auto-fil and auto-submit html form

Posted on 2009-07-02
7
531 Views
Last Modified: 2013-11-10
I've got a weird idea here and was wondering how to go about it.  (I have no idea as to where to start.)

I've got a web-form that enters data into a mysql database when the user submits.  I would like to program a php script to automagically fill in the info *and* submit it so that I can automate a whole bunch of entries (1000 for example) so I can have a ton of random sample data to work with for some other scripts that will pull this data and possibly try to trend it.

Just so we're 100% clear, I know I can do it from the shell easy enough, but the thought struck me "I wonder if I could do it this other way?"  So this is more of a curiosity than anything.
0
Comment
Question by:Tony O'Byrne
  • 4
  • 3
7 Comments
 
LVL 6

Author Comment

by:Tony O'Byrne
ID: 24767841
Just to elaborate a little...  When I said that I know it could be done from the shell easy enough, I meant that I could do php/mysql via the shell.  What I'm really curious about is php actually sending the information and submitting it as if the user had done it.  I guess I would be trying to get php to send a "post" request to the server?

As I said, I've no idea where to start and my above terminology may be ... terminal.  Terminal terminology. :-)
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24767843
Yes, you can post information to a script.  I use fsockopen() to do that.  I will post an example here for you in a moment. ~Ray
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24768009
I'm having some 404 issues getting it to post to a script in my web root, but I think that is server-related.  The theory is sound, since I use this with PayPal all the time.

You would take the code example here, and place it into an iterative loop to post all the data you wanted.

Best regards, ~Ray
<?php // RAY_post_example_fsockopen.php
error_reporting(E_ALL);
 
// THE SITE WE WANT TO TALK TO - IN THIS CASE, TO MY SITE
$server_url  = "www.your.org";
$server_url  = $_SERVER["HTTP_HOST"];
 
// THE PAGE INSIDE THE WEB SITE
$request_uri = "/RAY_dump_superglobals.php";
 
// THE POST DATA THAT WE WANT TO SEND
$dat = array(
    'name' => 'joe',
    'mail' => 'joe@your.org',
    'word' => 'secret'
   );
 
// CONSTRUCT THE POST STRING URLENCODED AND SEPARATED BY AMPERSANDS
$postdata  = '';
foreach ($dat as $key => $val)
{
    $postdata .= '&' . $key . '=' . urlencode($val);
}
$postdata = ltrim($postdata, '&');
 
// CONSTRUCT THE HEADERS
$header = '';
$header .= "POST $request_uri HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($postdata) . "\r\n\r\n";
 
// SHOW WHAT WE ARE GOING TO DO
echo "<pre>\n";
echo "REQUEST DATA FOLLOWS:\n";
var_dump($server_url);
var_dump($request_uri);
var_dump($postdata);
var_dump($header);
echo "</pre>\n";
 
 
// OPEN THE SOCKET TO THE PAGE
$fp = fsockopen ($server_url, 80, $errno, $errstr, 30);
 
// TEST FOR VERIFICATION
if (!$fp)
{
	die("HTTP ERROR $server_url $request_uri fsockopen() FAILED ERRNO=$errno ERRSTR=$errstr");
}
 
// HTTP OPEN - WRITE HEADER AND REQUEST
fputs ($fp, $header . $postdata);
 
// HTTP OPEN - READ RESPONSE
$reply = '';
while (!feof($fp))
{
	$reply	.= fgets($fp, 1024);
}
 
// SEE WHAT THE FOREIGN SITE SAID
echo "<pre>\n";
echo htmlentities($reply);
echo "</pre>\n";
 
// FINIS
echo 'Done!';
?>

Open in new window

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24768027
Here is the "catcher" script.
<?php // RAY_dump_superglobals.php
error_reporting(E_ALL);
 
// OPEN AN OUTPUT BUFFER
ob_start();
 
// SHOW THE SUPERGLOBALS
echo "\nGET ";   var_dump($_GET);
echo "\nPOST ";  var_dump($_POST);
echo "\nCOOKIE ";var_dump($_COOKIE);
 
// CAPTURE THE BUFFER
$vardump = ob_get_clean();
 
// SEND THE RESULTS
mail('you@your.org', 'VARDUMP', "$vardump");
 
// SHOW THE RESULTS
echo htmlentities($vardump);
?>

Open in new window

0
 
LVL 6

Author Comment

by:Tony O'Byrne
ID: 24768931
What's the "catcher" script for?
0
 
LVL 6

Author Closing Comment

by:Tony O'Byrne
ID: 31599373
Looks like this'll do. :-)  It gives me something to work off of which is what I was looking for.  If I have any further issues, I'll create a new thread.  Thanks for the help.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24769018
The catcher script will receive the POST data and print it out for you.

Thanks for the points - it's a great question, ~Ray
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question