Kaus
Kaus

Reputation: 67

how to redirect from one website to another website user home page after logging in?

I have 2 websites A & B. Every user has same login password for both websites A & B.

Now I want some specific users to land into(redirect to) B website's user home page after they login into the A website.

I dont want them to open the B website's login page separately for logging in.

If that specific user has logged in A website then he will be redirected to B website's user home page without doin login on B website. Can anybody help me out how to achieve this ?

EDIT - is there any way where i can post the login id password of user from A website's login page to B website's login page and then it fires the login button to redirect the user to B website's user home page in one go ?

Also, if i want to login into some external website for eg. like Gmail through my portal. Is there any way that the user logs in to my website and gets redirected to his Gmail home page ?

Upvotes: 1

Views: 3373

Answers (2)

Ravi Hirani
Ravi Hirani

Reputation: 6539

If you can connect Site A's DB via Site B

Then this suggestion will help you.

1) On site A

Redirection when user with email [email protected] is successfully logged in

$userEmail = md5([email protected]);
// Store below key to DB table of users whose email is [email protected]
$key = md5(microtime().rand()); 
header('Location: http://www.site-B.com/'."$key/$userEmail");
exit;

2) On site B,

Get $key and $userEmail Connect with site A's DB. and Run query like,

SELECT * FROM users WHERE MD5(email) = '$userEmail' AND key = '$key'

Get user and set session on site B. Then remove key from DB.

Upvotes: 1

Aslan Kaya
Aslan Kaya

Reputation: 524

You can do this with using few different methods.

Method 1: Using Cookies

Once the user is logged in to Site A you can write a cookie:

setcookie("SiteALoginTrue","True",time()+3600,"/",".Site-B-URL.com");
header("Location : Site-B-URL.com); // Redirect the website to siteB

and in your Site B code you will need to read the cookie while website loads.

Method 2: Using PHP in your SiteA login script you can save logged user IP with timestamp and after redirected to Site B you will need to another script that checks Site A database if the visted IP is logged in = true. Once site B finds that IP is marked Logged in database then you can create a logged in Session to avoid checking database every page refresh.

Upvotes: 5

Related Questions