Page 1 of 1

PHP Dom

Posted: Wed Jul 14, 2010 8:41 am
by thors1982
I have a weird project and i can't figure out how the PHP Dom works.

I need to load a url, type in a username/password and submit the form. Then go to another URL and parse the data. (The last URL is password protected, which is why I need to submit the form.

So I am able to load the first url find the input fill them out. I then need to submit the form and get the next url. Does anyone know how I can do that? I don't have much experience with the PHP dom library.

This is the code I have so far:

Code: Select all

$username = 'usernamegoeshere';
$password = 'passgoeshere';

$dom = new DOMDocument();
$dom->loadHTMLFile('https://urltologin.com');


$elements = $dom->getElementsByTagName('*');


if(!is_null($elements))
{
	foreach ($elements as $element)
	{
		echo "<br/>". $element->nodeName. ": ";

		if($element->nodeName == "input")
		{
			if($element->getAttribute('id') == "MerchantLogin")
			{
				echo "Found Login";
				$login_input = $element;
			}
			else if($element->getAttribute('name') == "Password")
			{
				$password_input = $element;
				echo "Found Password";
			}
			else if($element->getAttribute('value') == "Log In")
			{
				$submit_input = $element;
				echo "Found Submit Button";
			}
		}
	}
}

$login_input->nodeValue = $username;
$login_input->setAttribute("value", $username);
$password_input->setAttribute("value", $password);
$password_input->nodeValue = $password;
$submit_input->click();
$submit_input->submit();
Thanks for your help

Re: PHP Dom

Posted: Wed Jul 14, 2010 3:07 pm
by yacahuma
did you try curl? this link may give you a start

http://www.askapache.com/htaccess/sendi ... -curl.html