Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP read a cookie that is on another domain

Tags:

php

cookies

I have two domains. One domain contains the login script. It creates a cookie when logged in. Another domain have a URL shortener.

So, on the 2nd domain that have the URL Shortener script have a file called session.php. Usually I was using $_COOKIE['sessionid'] to get the session id and match it using database.

How can I get the session id now? I have tried few ways but none of them have solve my problem.

like image 921
Prasad N Avatar asked May 27 '10 09:05

Prasad N


2 Answers

For obvious security reasons, you can't read a cookie that belongs to another domain. You can do it across sub-domains though.

Why not append the session id to the forwarded URL?

like image 109
Andy E Avatar answered Nov 01 '22 04:11

Andy E


Have you considered using a SSO implementation?

http://www.jasig.org/cas

http://en.wikipedia.org/wiki/Single_sign-on

We use it at work, it's awesome! It means we don't have to worry about these types of problems.

like image 24
Flukey Avatar answered Nov 01 '22 02:11

Flukey