Reputation: 801
Using the same credentials, I am trying to log into two different locations from the one form. The reason for this is so that the second login (A CRM portal), can be loaded into an iframe without having to log in a second time. The solution that I thought would be best was to use an Ajax call to process one login and then after I get the response, go and process the second login. I'm using the client side to make the two calls because I need the cookies to be saved to the client’s browser. I use Ajax to make the call. I know that the cookies are being returned (I use an application called Fiddler to view the activity) but I don't know how to grab those cookies and save them to the clients browser?
Javascript / JQuery That I use:
<script type="text/javascript">
$(document).ready(function() {
$(".login_btn").click(function() {
$.ajax({
type: "POST",
url: "http://development/crm/processlogin.php",
data:"username="+ "[email protected]" + "&password="+ "password" + "&rememberme="+ "on",
success: function(data, textStatus){
alert("success: "+ JSON.stringify(data));
},
error: function(data, textStatus){
alert("error: "+ JSON.stringify(data));
}
});
});
});
</script>
Cookie response that I get, using "Fiddler" to view the information:
Response sent 44 bytes of Cookie data:
Set-Cookie: PHPSESSID=4a30p9g6mh5tm93a94o7bh7r74; path=/
Response sent 50 bytes of Cookie data:
Set-Cookie: WHMCSUID=75; expires=Thu, 07-Feb-2013 10:48:49 GMT
Response sent 79 bytes of Cookie data:
Set-Cookie: WHMCSPW=54512414f2e6aef246445abf341a05e9; expires=Thu, 07-Feb-2013 10:48:49 GMT
The message I get from the firebug console window:
POST http://development/crm/processlogin.php 302 Moved Temporarily 5.04s
The output:
error: {"readyState":0,"responseText":"","status":0,"statusText":"error"}
I believe that the 302 error message is because the server is trying to redirect after the log in. I don't actually need that redirect but I do need the cookies to be saved to the browser so that the user is logged in and I'm hoping that you guys can tell me how to do this?
Thanks!!!
Upvotes: 3
Views: 1280
Reputation: 801
I believe that cdm9002 was correct in saying that the reason it didn't work was due to the different domains. I tested the functionality on the same domain and it worked, however, this is not the functionality that I need. I've come up with a hack that makes it work but it's not the correct way of doing things :(. If anyone knows the correct way, I’m still interested, but I’ve sorted out my immediate dilemma.
The solution was to process the applications login first. Then load the next login credentials into a hidden iframe on the next page. I then used javascript to submit the hidden form.
I know that this is a very bad way of doing it but I was unable to come up with an alternative solution.
Upvotes: 1