473,804 Members | 3,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keeping session data across two domains

Hi,

I'm using PHP 4.4.4. I have two domains -- www.mydomain1.com and
www.mydomain2.com. Both point to the same IP address. I have two
pages on that IP -- first.php

<?php
session_start() ;
$_SESSION['test'] = "hello";
?>

and second.php

<?php
session_start() ;
print $_SESSION['test'];
?>

What I would like is when I first visit http://www.mydomain1.com/first.php
and then visit http://www.mydomain2.com/second.php to have the word
"hello" printed. Does anyone know how to adjust the above scripts or
my environment to make this possible?

Thanks, - Dave

Sep 24 '07 #1
3 8301
C.
On 24 Sep, 20:58, "laredotorn...@ zipmail.com"
<laredotorn...@ zipmail.comwrot e:
Hi,

I'm using PHP 4.4.4. I have two domains --www.mydomain1.c omandwww.mydoma in2.com. Both point to the same IP address. I have two
pages on that IP -- first.php

<?php
session_start() ;
$_SESSION['test'] = "hello";
?>

and second.php

<?php
session_start() ;
print $_SESSION['test'];
?>

What I would like is when I first visithttp://www.mydomain1.c om/first.php
and then visithttp://www.mydomain2.c om/second.phpto have the word
"hello" printed. Does anyone know how to adjust the above scripts or
my environment to make this possible?

Thanks, - Dave
I'll assume you're using cookies for sessions. In which case the
question is how you get a cookie from one site set when you are
accessing another.

The solution is to suck in pages from both mydomain1 and mydomain2 at
the point where the session is established. This could be done with
frames or by redirection. Life's probably a lot simpler if you pass
across the generated session id from one to the other, but you need to
be wary of session fixation. Otherwise you'll probably need to write
your own session handler to maintain 2 sessions alive and in sync.

HTH

C.

Sep 24 '07 #2
On Sep 24, 3:51 pm, "C." <colin.mckin... @gmail.comwrote :
On 24 Sep, 20:58, "laredotorn...@ zipmail.com"

<laredotorn...@ zipmail.comwrot e:
Hi,
I'm using PHP 4.4.4. I have two domains --www.mydomain1.c omandwww.mydoma in2.com. Both point to the same IP address. I have two
pages on that IP -- first.php
<?php
session_start() ;
$_SESSION['test'] = "hello";
?>
and second.php
<?php
session_start() ;
print $_SESSION['test'];
?>
What I would like is when I first visithttp://www.mydomain1.c om/first.php
and then visithttp://www.mydomain2.c om/second.phptohav e the word
"hello" printed. Does anyone know how to adjust the above scripts or
my environment to make this possible?
Thanks, - Dave

I'll assume you're using cookies for sessions. In which case the
question is how you get a cookie from one site set when you are
accessing another.

The solution is to suck in pages from both mydomain1 and mydomain2 at
the point where the session is established. This could be done with
frames or by redirection. Life's probably a lot simpler if you pass
across the generated session id from one to the other, but you need to
be wary of session fixation. Otherwise you'll probably need to write
your own session handler to maintain 2 sessions alive and in sync.

HTH

C.- Hide quoted text -

- Show quoted text -
Thanks for your response, C. Regarding
Life's probably a lot simpler if you pass
across the generated session id from one to the other
hate to be dense, but how do you do that? - Dave

Sep 24 '07 #3
C.
On 24 Sep, 21:59, "laredotorn...@ zipmail.com"
<laredotorn...@ zipmail.comwrot e:
On Sep 24, 3:51 pm, "C." <colin.mckin... @gmail.comwrote :
On 24 Sep, 20:58, "laredotorn...@ zipmail.com"
<laredotorn...@ zipmail.comwrot e:
Hi,
I'm using PHP 4.4.4. I have two domains --www.mydomain1.c omandwww.mydoma in2.com. Both point to the same IP address. I have two
pages on that IP -- first.php
The solution is to suck in pages from both mydomain1 and mydomain2 at
the point where the session is established. This could be done with
frames or by redirection. Life's probably a lot simpler if you pass
across the generated session id from one to the other, but you need to
be wary of session fixation. Otherwise you'll probably need to write
your own session handler to maintain 2 sessions alive and in sync.
HTH
C.- Hide quoted text -
- Show quoted text -

Thanks for your response, C. Regarding
Life's probably a lot simpler if you pass
across the generated session id from one to the other

hate to be dense, but how do you do that? - Dave
When you start the session on, say domain1, include an iframe with a
hidden div, and pass the sessionid to a page in domain2 which sets a
session cookie:

e.g. www.domain1.com/logged_in.php...

<?php
if (session_id()== '') {
create_new_sess ion=true;
}
session_start() ;

// .... start doing the page header and body...

// ... at the very end of the page, before the </bodytag....

if (create_new_ses sion) {
session_commit( );
$url="www.domai n2.com/sync_session.ph p?usesess=";
$url.=base64enc ode(encrypt(ses sion_id() . '/' . time(),
's3cr3t'));
// I've not spelled out how to use mcrypt
print "<iframe src=\"$url\" style=\"width:1 0px;height:5px\ "></
iframe>\n";
// nor added the css to make it invisible
}
?>

.....and www.domain2.com/sync_session.php:

<?php

$request_sessio n=decrypt(base6 4decode($_GET['usesess']), 's3cr3t');
list($use_id,$r equested)=explo de('/',$request_sess ion);

if ($requested<tim e()+10) {
// allow a 10 second window to reduce probability of replay attacks
// although a more complete solution would be to set a session
variable in domain1 as a visa and
// reset it here.
set_cookie(sess ion_name(), $use_id);
print "OK, using same session id";
} else {
print "Invalid sync request";
}

?>

....or something like that. Not tested - YMMV.

C.

Sep 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4474
by: d.schulz81 | last post by:
Hi all, We have about 10 different domains that are linked very closely and we want to identify and keep track of every single user that surfs our websites by the use of sessions. The problem is how to keep track of the session ID across domains. - cookies don't work because not acepted by 40 % of or users and cookies don't work across domains
6
3956
by: Astra | last post by:
Hi All I've noticed on quite a few ASP sites that when they have a 'MyAccount' section they transfer the site to https and then when you have logged into your account successfully and gone back to the majority of the site you move back to http whilst still being logged in. I've used the Session var method before to check if a user can have access to pages, but how on earth can I keep a handle on this when I flip the user between my...
4
2566
by: Le | last post by:
Hello I was wondering if there was a way to keep a user's session info across multple domains For example, company A owns website www.a.com and www.b.com. A user logs into www.a.co and later visits www.b.com. I would like to have it where the user doesn't have to login again. Thank Le
11
3428
by: Vic Spainhower | last post by:
Hello, I just purchased a new domain name and I've set it up as a redirect to a folder on my main site. What is happening is the index.php page checks a session variable to see if the user is logged on and if not it displays a login screen. However, after loggin in it just keeps coming back to the login screen because the session variables are getting lost. I inserted "session_write_close()" prior to the header("Location:...
7
3028
by: Seth | last post by:
I have noticed that the id of my session object changes when I switch from a non-secure to a secure connection. What I'm trying to do: I have a cookie that is built on the non-secure side of things. What I need to do is to switch to a secure connection and then later on while still in that secure connection delete the cookie that was created on the non- secure side. I need to do this because I can not reference the non-secure cookie...
1
2685
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
7
7778
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because ASP.NET always sets the Session cookie domain to the full domain (e.g. "www.mydomain.com") instead of the parent domain (e.g. "mydomain.com") The problem with this is when the visitor goes to a different sub-domain (e.g. "search.mydomain.com"),...
13
8679
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 a login to show data. I want the user to login only once when he visits any of my domains.
9
7817
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 in sessions? I can see active sessions in my mysql database, but is that the only place this information is stored? Sessions and cookies I know are related also, but how specifically (session info stored in cookies?)? Right now, when users...
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
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 we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.