So, what I want to do, is make a script that will automatically add my login info(which i will have in my database) to whatever form I want.
To do this, I get the html source from the website(using cURL) then with DOMdocument i'm editing the input's username and password form name with my username and password values, then I'm outputing this, and click login
All should be alright, right? Yeah, in theory, but it isn't.
This is the code that does right that:
$dom = new DOMdocument();
$dom->formatOutput = true;
@$dom->loadHTML( mb_convert_encoding($html, 'HTML-ENTITIES', $encoding) );
$inputs = $dom->getElementsByTagName('input');
foreach ($inputs as $input)
{
if ($input->getAttribute('name') == $id_nameValue)
{
$new_input = $dom->createElement('input');
$new_input->setAttribute('name', $id_nameValue);
$new_input->setAttribute('value', $id_value);
$input->parentNode->replaceChild($new_input, $input);
}
if ($input->getAttribute('name') == $password_nameValue)
{
$new_input = $dom->createElement('input');
$new_input->setAttribute('name', $password_nameValue);
$new_input->setAttribute('value', $password_value);
$new_input->setAttribute('type', 'password');
$input->parentNode->replaceChild($new_input, $input);
}
}
echo $dom->savehtml();
The problem I'm having, is with javascript not loading or css, or not redirecting correctly...
Lets take for example reddit: https://ssl.reddit.com/login They have this for the CSS
<link rel="stylesheet" href="/static/reddit.cYdhnJIJSZ0.css" type="text/css" />
instead of having https://ssl.reddit.com/login/static/reddit.cYdhnJIJSZ0.css, so I cant load it correctly, because it uses my url like
MY_URL.com/static/reddit.cYdhnJIJSZ0.css to find it...
The same applies to javascript, like
<script type="text/javascript" src="/static/jquery.js">
Or with
<form id="login_login" method="post" action="/post/login" class="user-form login-form">
this would redirect me to MY_URL.com/post/login
My question is how can I make this work? How can I edit the links to include the websites url? Since this is the first time i'm using DOMdocument, I don't know how would I go about editing the form, or script src...
So my end result would be
<link rel="stylesheet" href="https://ssl.reddit.com/login/static/reddit.cYdhnJIJSZ0.css" type="text/css" />
<script type="text/javascript" src="https://ssl.reddit.com/login/static/jquery.js">
<form id="login_login" method="post" action="https://ssl.reddit.com/login/post/login" class="user-form login-form">