PHP Dom

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
thors1982
Forum Newbie
Posts: 1
Joined: Wed Jul 14, 2010 8:35 am

PHP Dom

Post 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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: PHP Dom

Post by yacahuma »

did you try curl? this link may give you a start

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