473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHPSESSID problem

I have a page that contains just

<?php
session_start();
$_SESSION['test'] = 'HELLO';
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '../listings/store.php';
header("Location: http://$host$uri/$extra");
exit;
?>

store.php would then start with:

<?php
session_start();
echo($_SESSION['test']);
// and so on
?>
The purpose of the page is just to do a re-direct but is needed.

The problem I have is this:

If a user comes to my site with: www.mysite.com and then visits
the above re-direct script/page all is well and the page store.php can do

echo($_SESSION['test']); and get HELLO out.

BUT

If the user comes to the site with just mysite.com
PHP sets TWO PHPSESSID cookies : one for mysite.com and another for
www.mysite.com

This causes the $_SESSION['test'] variable to be lost.

Hard coding the re-direct page can't cure this for me.

Can anyone shed any light or help me prevent the second PHPSESSID from
losing the variable please?

thanks.

nigel.

Oct 9 '06 #1
5 3446

<ni*****@by.ukwrote in message
news:MP************************@news-text.blueyonder.co.uk...
>I have a page that contains just

<?php
session_start();
$_SESSION['test'] = 'HELLO';
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '../listings/store.php';
header("Location: http://$host$uri/$extra");
exit;
?>

store.php would then start with:

<?php
session_start();
echo($_SESSION['test']);
// and so on
?>
The purpose of the page is just to do a re-direct but is needed.

The problem I have is this:

If a user comes to my site with: www.mysite.com and then visits
the above re-direct script/page all is well and the page store.php can do

echo($_SESSION['test']); and get HELLO out.

BUT

If the user comes to the site with just mysite.com
PHP sets TWO PHPSESSID cookies : one for mysite.com and another for
www.mysite.com

This causes the $_SESSION['test'] variable to be lost.

Hard coding the re-direct page can't cure this for me.

Can anyone shed any light or help me prevent the second PHPSESSID from
losing the variable please?
You could always use a htaccess redirect to ensure that people who came to
yoursite.com would be redirected to www.yoursite.com

Oct 10 '06 #2
In article <eg**********@emma.aioe.org>, su****@flexiwebhost.com says...
>
<ni*****@by.ukwrote in message
news:MP************************@news-text.blueyonder.co.uk...
I have a page that contains just

<?php
session_start();
$_SESSION['test'] = 'HELLO';
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '../listings/store.php';
header("Location: http://$host$uri/$extra");
exit;
?>

store.php would then start with:

<?php
session_start();
echo($_SESSION['test']);
// and so on
?>
The purpose of the page is just to do a re-direct but is needed.

The problem I have is this:

If a user comes to my site with: www.mysite.com and then visits
the above re-direct script/page all is well and the page store.php can do

echo($_SESSION['test']); and get HELLO out.

BUT

If the user comes to the site with just mysite.com
PHP sets TWO PHPSESSID cookies : one for mysite.com and another for
www.mysite.com

This causes the $_SESSION['test'] variable to be lost.

Hard coding the re-direct page can't cure this for me.

Can anyone shed any light or help me prevent the second PHPSESSID from
losing the variable please?

You could always use a htaccess redirect to ensure that people who came to
yoursite.com would be redirected to www.yoursite.com
Thanks for the idea peter but that doesn't do it I'm afraid as I'd need
the redirect everywhere on the site.

This is turning into a worrying problem here. Fortunately we havn't
implemented passwords with PHP sessions! That would have been a disaster.

nigel.

Oct 10 '06 #3
Thanks for the idea peter but that doesn't do it I'm afraid as I'd need
the redirect everywhere on the site.

This is turning into a worrying problem here. Fortunately we havn't
implemented passwords with PHP sessions! That would have been a disaster.
you only need do it once in your root folder in a .htaccess file and it will
work for all pages.
Oct 10 '06 #4
In article <eg**********@emma.aioe.org>, su****@flexiwebhost.com says...
>
Thanks for the idea peter but that doesn't do it I'm afraid as I'd need
the redirect everywhere on the site.

This is turning into a worrying problem here. Fortunately we havn't
implemented passwords with PHP sessions! That would have been a disaster.

you only need do it once in your root folder in a .htaccess file and it will
work for all pages.
Not if people never go to that page peter. It would need to be in every
folder we have a web page in. According to the PHP docs this would
generate a massive performance and memory hit.

Oct 11 '06 #5
ni*****@by.uk wrote:
In article <eg**********@emma.aioe.org>, su****@flexiwebhost.com says...
>>>Thanks for the idea peter but that doesn't do it I'm afraid as I'd need
the redirect everywhere on the site.

This is turning into a worrying problem here. Fortunately we havn't
implemented passwords with PHP sessions! That would have been a disaster.

you only need do it once in your root folder in a .htaccess file and it will
work for all pages.

Not if people never go to that page peter. It would need to be in every
folder we have a web page in. According to the PHP docs this would
generate a massive performance and memory hit.
Incorrect.

Apache searches the current directory and all directories above it (up
to your document root). A .htaccess file in your root directory will
affect all pages in your site.

And it can be a slight performance hit, but unless you have a large
..htaccess file or your server is already way overloaded you shouldn't
notice any difference.

If that is still a concern to you just place it in your httpd.conf.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 11 '06 #6

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

Similar topics

8
by: JohnS | last post by:
Hi, When I initially start my browser (any of 'm) and point it to my PHP script the $PHPSESSID is always blank. On all subsequent hits or after a refresh the value for $PHPSESSID is fine... why...
4
by: Arnaud | last post by:
Hi ! I would like to propagate data between php pages, in two cases : the pages are read by : 1- Internet Explorer It's ok, data are writen in one page, and read from another. I don't use...
3
by: edward hage | last post by:
Hello , I want to pass some $_SESSION data to another page. I can pass PHPSESSID along using echo '<br /><a href="page2.php?' . SID .. '">page 2</a>'; However, I want to fill in a table...
0
by: Alex Shi | last post by:
Hi, I don't know how php process its session. I just noticed that for the first time a web site is loaded php will insert a PHPSESSID through out the page: it attach this id to links, insert...
2
by: Arnaud | last post by:
Hi, I would like to protect myself against these two PHPSESSID I have sometimes in the url... I'm coding a session-based script which will be upload on a shared server. I can't control if this...
7
by: windandwaves | last post by:
Dear Gurus Is it correct that you do not have to pass the PHPSESSID in the header in order to keep a session going. What are the advantages/disadvantages of having the PHPSESSID in the header ...
2
by: frizzle | last post by:
Hi there I have a site in which all pages ARE php-pages, but they're called/manipulated with htaccess. All files appear as a html-file to surfers. Sometimes i get the PHPSESSID declared in the...
0
by: John Smith | last post by:
Googlebot has been picking up numerous PHPSESSID name/value pairs in URIs at my website, and this causes duplicate hits and wasted bandwidth. I've since prevented PHPSESSID generation in my PHP...
29
by: CAH | last post by:
Hi Can you avoid that googlebot indexes PHPSESSID pages? Googlebot is indexing pages with PHPSESSID, which makes it think my page has a infinite number of pages. How can one avoid this? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...

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.