Solved

PHP auto-fil and auto-submit html form

Posted on 2009-07-02
7
538 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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 110

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 110

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 110

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article discusses four methods for overlaying images in a container on a web page
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

717 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