Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2003, 07:08 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP Session passed to different sub domains

Hi there,

Could someone tell me how to pass a session cookie to different subdomains, without passing it in url.
Thanks in advance.

Regards,

Gera

 
Old November 6th, 2003, 07:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can configure PHP to use a specific cookie domain/path. I'm pretty sure (not positive, so this will require you to test it yourself) that if you only specify a host and tld (e.g. '.wrox.com'), the cookie will be available for all sub-domains.

For more info, read through the following manual pages (and the informative external links in them):
  http://www.php.net/session
  http://www.php.net/setcookie

The configuration option in PHP.ini that you want to look for is "session.cookie_domain".


Take care,

Nik
http://www.bigaction.org/
 
Old November 6th, 2003, 08:28 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Nik,

I've already found the answer in php docs
http://www.php.net/manual/en/function.setcookie.php
will try it tonight.

Thanks for your help.
Regards,
Gera

 
Old November 6th, 2003, 10:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

setcookie() is a function that allows you to set a cookie variable, but you have to be careful about messing up your original session variable. If PHP handles setting and retrieving your session ID in a cookie, you're probably best off configuring PHP to create a cookie that works across sub-domains.

If you have written your own session handling functions (and, in my opinion, it sounds like a good idea for your multi-domain site to do so, especially if each domain is on a different machine. If you're using the same database server to store all your session data, you can use a cookie to store the session ID for all sub-domains, and each server uses the same session handling functions and database server to access that user's session.

If I'm not making sense, let me know.


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help with php variable passed to perl... nriv08 Beginning PHP 0 October 9th, 2008 12:54 PM
Keep session between different domains CenturiMan ASP.NET 2.0 Professional 0 March 21st, 2006 10:19 AM
Session Error in PHP Randhy MySQL 8 December 17th, 2004 07:49 AM
Can't display input variable passed on to php code mespejo Beginning PHP 2 November 25th, 2003 03:32 PM
form data not passed to php keng BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 September 4th, 2003 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.