473,466 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to share a session with other websites(subdomains) ?

9 New Member
hi all,

I want to use session for storing username & password.
I will have a main page mainpage.mydomain.com which will save username+password in a session on the server.

Now when i access email.mydomain.com i want it to retrieve the username+password from the session previously created by mainpage.mydomain.com.

The web applications are hosted on the same machine using apache virtual hosts.
Someone plz advise...

thanks
Mar 30 '10 #1
9 4491
chathura86
227 New Member
If you want to be able to pass session data between subdomains you need to add/modify the following to the php.ini file.

session.cookie_domain = .mydomain.com

If you are unable to modify the the php.ini file you can add the following before the session.start() function on any page which creates the session cookie.

ini_set("session.cookie_domain", ".mydomain.com");
Mar 30 '10 #2
coolatt
9 New Member
thanks for replying.

but how do i make email.mydomain.com access the data stored in the session created by mainpage.mydomain.com ?

I want the mainpage domain to store username+password.
in session_test.php i put:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $_SESSION['userName'] ="MyUserName";
  4. $_SESSION['password'] ="MyPassword";
  5.  
  6. print "Session Test";
  7.  
  8. ?>
  9.  
  10.  
then in session_show.php i put :
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. if(isset($_SESSION['userName']))
  4. {
  5.   print "Session id: ".session_id()."<br>";
  6.   print "Your session username: ".$_SESSION['userName']. "<br>";
  7.   print "Your session password: ".$_SESSION['password']."<br>";
  8. }
  9. else
  10. {
  11.   print "Session does not exist";
  12. }
  13. ?>
  14.  
  15.  
when i run the above test i get the session id.
Mar 30 '10 #3
chathura86
227 New Member
just do one of the step which i have mentioned above

after that you can use it as it is,
i mean set $_SESSION['foo'] = "bar"; in one domain
and you can get it from the other domain
by $_SESSION['foo']

no other modifications are required

Regards
Mar 30 '10 #4
coolatt
9 New Member
both email.mydomain.com & mainpage.mydomain.com are already using sessions.

I tried to put the following code in email.mydomain.com but it didnt print theh username & password:

Expand|Select|Wrap|Line Numbers
  1. if(isset($_SESSION['userName']))
  2. {
  3.   print "Session id: ".session_id()."<br>";
  4.   print "Your session username: ".$_SESSION['userName']. "<br>";
  5.   print "Your session password: ".$_SESSION['password']."<br>";
  6. }
  7.  
  8. else
  9. {
  10.   print "I cannot retrive data from another domain's session";
  11. }
  12.  
Is it because email.mydomain.com is already using session ??
Mar 30 '10 #5
chathura86
227 New Member
which method you used ?

editing the php.ini or setting it on the php code?

Regards
Mar 30 '10 #6
coolatt
9 New Member
editing the php.ini
/////////////////////////
Mar 30 '10 #7
chathura86
227 New Member
then the session should be shared on the sub domains also. but remember to restart apache after changing the php.ini

Regards
Mar 31 '10 #8
coolatt
9 New Member
yes i had restarted apache. any other steps i have to follow to make it work ?
plz advise on this.
Mar 31 '10 #9
coolatt
9 New Member
it does not work when both domains implement their own session management :-(
Apr 1 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: onetitfemme | last post by:
Domain are very cheap now adays. What would be the pros and cons of using different hosts served from the same server, say: www.blogyourbrainoff.com and www.yourbusiness.com
0
by: Rahul T via .NET 247 | last post by:
(Type your message here) Hi, I have an application in ASP.NET consisting of mutliplesubdomains. Each subdomain is implemented as a separate projectin Visual Studio.NET and they are all part of the...
1
by: guoqi zheng | last post by:
I have an application in IIS with a few sub domains assign to it. Is there a way for me to share session data across those subdomains? regards, Guoqi Zheng http://www.ureader.com
3
by: craigkenisston | last post by:
In an application I'm developing I will be using subdomains in the main website to hold some sections of the sites. There will be many serverside generated links that will point to this...
4
by: radiax | last post by:
Is there a way to associate or bind a subdomain to a tcp sockets under .net framework (vb.net / c#). I know ip address can be used when using sockets, but the problem is the ip address is shared...
1
by: Hans Kesting | last post by:
Hi, Is it possible to share sessions between subdomains? Say: the user logs in at www.company.com, and is redirected to my.company.com. This is a different url for the same application. Can I...
1
by: loooser | last post by:
Hi, I would just like to know if there is a way to let php keep sessions accross subdomains? I mean sessions with cookies, where the domain should be correctly set. Or maybe I can use SID...
13
by: Samir Chouaieb | last post by:
Hello, I am trying to find a solution to a login mechanism for different domains on different servers with PHP5. I have one main domain with the user data and several other domains that need...
1
by: daniel.westerberg | last post by:
Is it possible to keep sessions between subdomains? I.e If I have a site "shop.com" and when user acess his personal page it's "secure.shop.com" Is it possible to share the session values between...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.