Jump to content

PHP Newbie needs help submitting form data


shockerfred

Recommended Posts

Hello, I am just getting interested in PHP, so please excuse my ignorance. Something I thought might help me learn is this challenge. http://penn-station.com/gift2010.php is a daily enter sweepstakes. I'm wanting to automate a daily entry. I was able to do so using AutoIT (windows automation), but the result was rather janky. Anyways, I found how to enter my name in the Name field of the form by modifying the value attribute of the textbox. (I used Chrome's DOM inspector plug-in)

 

<input type="text" class="EH_Form_Textbox" name="Name" size="30" value="Fred">

 

How would I go about actually submitting this?

 

Thank you very much,

Fred

Link to comment
Share on other sites

I'm not sure where I want to send the data. My goal is to automatically enter the contest without manually typing in my information. I assumed PHP would be the best way to do it. Is there a way to do this in PHP? Take a look at the link to the entry page and let me know what you think.

 

Thanks,

Fred

Link to comment
Share on other sites

The way I would do is create a page, use AJAX request to a PHP page that uses cURL to post the data, then call the AJAX javascript function using window.setinterval(function, interval). Open the page and it will submit the form every so many miliseconds you supply. Dont get crazy with it or you will crash a server.

Link to comment
Share on other sites

OK Im bored so I created an example for you. 3 seperate pages and a folder called tmp.

 

mainpage.html:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="ajax.js">
</script>
<script type="text/javascript">
window.setInterval("wincontest()", 10000);
</script>
</head>
<html>
<body>
Keep Submitting!
<div id="page"></div>
</body>
</html>

 

ajax.js:

 

function wincontest(){
var ajaxRequest;  // The variable that makes Ajax possible!

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
		}
	}
}
// Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		document.getElementById('page').innerHTML = ajaxRequest.responseText;
	}
}

ajaxRequest.open("GET", "curl.php", true);
ajaxRequest.send(null); 
}

 

curl.php:

 

<?php
$tlds = array("com", "net", "gov", "org", "edu", "biz", "info");

  // string of possible characters
  $char = "0123456789abcdefghijklmnopqrstuvwxyz";


    // choose random lengths for the username ($ulen) and the domain ($dlen)
    $ulen = mt_rand(5, 10);
    $dlen = mt_rand(7, 17);

    // reset the address
    $email = "";

    // get $ulen random entries from the list of possible characters
    // these make up the username (to the left of the @)
    for ($i = 1; $i <= $ulen; $i++) {
      $email .= substr($char, mt_rand(0, strlen($char)), 1);
    }

    // wouldn't work so well without this
    $email .= "%40";

    // now get $dlen entries from the list of possible characters
    // this is the domain name (to the right of the @, excluding the tld)
    for ($i = 1; $i <= $dlen; $i++) {
      $email .= substr($char, mt_rand(0, strlen($char)), 1);
    }

    // need a dot to separate the domain from the tld
    $email .= ".";

    // finally, pick a random top-level domain and stick it on the end
    $email .= $tlds[mt_rand(0, (sizeof($tlds)-1))];
    $yourname = "Your+Name";

$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init();

// Follow any Location headers
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, COOKIE, "Cookie: __unam=f6ac6fd-12cebc488cb-43c9db21-1; __utma=105633695.1157431643.1292445715.1292445715.1292445715.1; __utmb=105633695; __utmc=105633695; __utmz=105633695.1292445715.1.1.utmccn=(referral)|utmcsr=penn-station.com|utmcct=/gift2010.php|utmcmd=referral");
curl_setopt($ch, CURLOPT_URL, 'http://mobileexp.com/cgi-bin/EventHandler/EventHandler.pl');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Alert cURL to the fact that we're doing a POST, and pass the associative array for POSTing.
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, "filename=gift10&id=national&action=SubmitEntry&Name=" . $yourname . "&Email=" . $email . "&RulesAgreed=checked&EntrySubmitButton=Submit");

$output = curl_exec($ch);
curl_close($ch);
echo "Email Submitted: " . $email;
print $output;
?>

 

You can ignore all the stuff at the top of curl.php if you want and just put $email = "youremail@youremail.com"; This just creates a random email. This entry only allows one a day so you either need to  loop through a list of emails or set the interval to once a day :) You have to have a page open to do anything in PHP, its not a locally installed system you can just do something "auto" without at least invoking a page. Hope this helps. Tip: google PHP cURL tutorial to get some help on webcrawling, you can do all kinds of cool stuff with it. Using Firefox and HTTPLiveHeaders addon makes cURL easy!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.