简体   繁体   中英

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 ?

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.

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 user@gmail.com is successfully logged in

$userEmail = md5(user@gmail.com);
// Store below key to DB table of users whose email is user@gmail.com
$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM