Jump to content

Recommended Posts

I would like to create a script that will login to a website and then allow the user to continue and browse as they wish.  I have a few business logins that I don't want to give to my staff. I don't want them to login from home or give out the credentials to unauthorized personnel, etc.

 

I would like the solution to be on our central inhouse server and not installed or modified on  individual workstations. Password autofill programs,  keypress programs or macros are not acceptable solutions.

 

I can login to a website using cURL, but I don't know how to transfer the logged in session to the user.  I can't create a copy of the target site's login page because they use realtime identifiers for each login. I need to "browse" to *their* login page, input the login credentials, submit, and then browse the site in the same session.

 

Please provide sample code that will demonstrate this login. I would like the solution to be PHP, but it does not have to use cURL.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/191105-php-autologin/
Share on other sites

I really doubt anyone will code this for you. If you are not willing to do the searching / put for the effort post in the freelance section and offer to pay someone for their troubles.

 

If you are willing to put forth effort, here is a site I found by google:

http://www.trap17.com/index.php/automatic-login-curl_t38162.html

 

That should help you in your quest.

Link to comment
https://forums.phpfreaks.com/topic/191105-php-autologin/#findComment-1007711
Share on other sites

:shrug: I am sorry that it came off that i did not want to do any work. That is not true and any help you can give me is appreciated.  I actually have spent alot of time on this, including the page that you found and i used that VERY code on a couple of my attempts. 

The problem I have is accessing the session created by curl.  I tried logging using that script, then doing a redir, but then that creates a new session which the site does not recognize as authenticated.  My code is below:

 

If the solution is easy then I am missing it.

 

<?php
// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'https://www.assuranthealthsales.com/414/sales/Login.aspx');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
$sTarget = "&TARGET=".urlencode("/414/sales/Agent/PostAgentLogin.aspx");
$sAuthReason = "&SMAUTHREASON=0";
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=myusername&password=supersecret'.$sTarget.$sAuthReason);

// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'assurantmain.txt');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT]']);


// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);

// CLOSE CURL
curl_close ($ch);

//move to the main landing page after login.
header("Location:https://www.assuranthealthsales.com/414/sales/Agent/AgentMenu.aspx");
exit;

?>

 

The only thing I can think to do is to create an iframe and control it through the Document interface. is there a better way?

Link to comment
https://forums.phpfreaks.com/topic/191105-php-autologin/#findComment-1007859
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.