开发者

Posting, Login in and redirecting for user

Here is the scenario: when the user is clicking on a link on my webpage i want to perform a login to another site, and use the cookies to login the user to the second site.

I'm using PEAR Request2 and i'm able to get the login cookies but when i use:

setcookie($cookies['1']['name'], $cookies['1']['value'], time()+3600, '/');

header("Location: http://www.example.com");

the cookie开发者_运维问答 host is my site and i suspect that is why i get a login error.

Is there anyway to issue a cookie as the secondary site - or do you have any suggestion how can i simulate login (i have all the relevant information) and redirect the user to home page?


Your script can pass some key to other site in private channel. after that you redirect to:

http://your.other.site.com/login.php?auth_key=$auth_key

And other site can auth_user. But be carefull, you need every time generate random key and make sure that user can use this key only one time.


You can use the setcookie like normal, but with just adding the domain of the cookie.

setcookie('cookiename','value',time()+3600,'/','.example.com');

However this is not suggested at all because it can open security risks.

http://php.net/manual/en/function.setcookie.php


Figured it out! you can only set the cookie on the client side for your domain.

I was fetching the cookies from a 3rd party website and tried to set those cookies, this can only b done using javascript :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜