3

I have to program an application where the users can connect to other websites. For example, the user clicks on the "Amazon" button and the application opens the Amazon website. It then needs to pre-populate the login and password information for the user. (The user added that info to my data base previously.)

My application is in PHP. I have tried using curl to implement this. I can connect, but the cookie is not then used by the users browser. My problem is a lot of websites are protected with tokens and their is a wide variety of different URLs

I have also tried another solution: the application would only fill in the user and password and the user click on "validate" or "login". After researching this, I've found that it may be more difficult. I haven't found any explication about how to fill a form in another website. I think browsers can do it, and I've seen applications such as 'Dashlane' that can do it to, so I think it should be possible.

How do I implement this feature?

  • You'll have to explain your situation better. What do you mean by "connect"? Do you want to put a link to the website so that the user visits it? Do you want to pull data from the other website client side? Do you want ot pull data from the other website server side? – Stephen Ostermiller May 21 '15 at 10:16
  • I put a link to the website then there are 2 options: 1) I send login and password with a form to the website server for connect the user 2) I fill login and password to the other siteweb client and the user click on "validate". Mozilla Firefox do the second method but it's a navigator... Can you help me please? – Deyanos May 21 '15 at 11:31
  • Are you asking how you log a user into another website? Can you tell us more about why you want to do that and what you expect to be able to do once the user is logged in? – Stephen Ostermiller May 21 '15 at 13:27
  • The users of this application use a lot of websites. For the websites, they have a difficult login and a password of 16 characters, so it's very difficult for them and they waste time. My mission is save employeer's time. When they are in their website, they just do what they need, my application don't look it. I ask how I log or how I can fill the differements inputs for them (Firefox do it, Dashlane too, but I don't know how they works) – Deyanos May 21 '15 at 13:51
  • I'm going to attempt to edit your question to make it clearer. Please fix anything I get wrong. – Stephen Ostermiller May 21 '15 at 13:59
2

You're on the right track with CURL.

What you need to do is add code that reads the website as if it's a basic HTML file then process the file replacing certain HTML code.

If some websites are basic with little to no javascript and contain a login box, then look for code containing something like:

<input type="text" name="username">

and replace it (using PHP's str_replace) with:

<input type="text" name="username" value="importedusername">

and do the same with the password field:

<input type="password" name="password">

and replace it (using PHP's str_replace) with:

<input type="password" name="password" value="importedpassword">

Here's a script to help you get started provided your PHP config is set to allow URLs in file functions, and that the website codes the username and password like I coded it above:

<?php
$myuser="usernametouse";
$mypass="passwordtouse";
$webpage=file_get_contents("http://example.com/loginpage");
$webpage=str_replace('<input type="password" name="password">','<input type="password" name="password" value="'.$mypass.'">',$webpage);
$webpage=str_replace('<input type="text" name="username">','<input type="text" name="username" value="'.$myuser.'">',$webpage);
echo $webpage;
?>

Because website publishers are free to order the parameters in the HTML tags to their liking, the code I present may need to be modified in order to adapt to each site.

For example, They could use:

<input name="username" type="text">

instead of:

<input type="text" name="username">

and if they do that, my code will then need to be modified.

Also, my code does not add any HTML headers. You should however define some with the header() command for better output speed. and place them before the final echo statement in my code.

  • Thank you for your answer ! I have already done it. I use DomElement, a PHP's library. With DomElement, I can use the html as javascript (fonctions getElementsByTagName etc.). When the website use a token system there are 2 tokens: 1 in a cookies when you visit the page, and the other in the form. The tokens need to be equal, but with this method they aren't. I have form's token in my form, so file_get_contents don't use cookie of browser. – Deyanos May 22 '15 at 7:26
0

I have maybe a solution. VBScript could fill login, because it can to have action on system.

<script language="VBScript">
    document.write "<h1>Et ceci du VBscript</h1>"
     Set objIE = CreateObject("InternetExplorer.Application")

    objIE.Navigate "about:blank"
    objIE.Visible = true
    objIE.Navigate "www.google.com"

    </script>

But I put this code in a html page and I open this page with IE. So i don't want it create a new IE.application. I want it use the IE opened.

Could you help me again please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.