Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2007-05-14 13:38:40
- bsw1971
- New Member
- Registered: 2007-05-14
- Posts: 4
php session dying when opening articles
I have the following in my default and archive templates:
<txp:php>
session_start();
if (!isset($_SESSION[‘valid_user’])) {
die(‘Restricted access’);
}
</txp:php>
It works fine on the main blog page all the time (as well as all of my other basic pages — TP is installed in a subdirectory), but if I try to open an individual article it’s losing the session value, so the article won’t display. I’ve browsed the forum, but I couldn’t find anything that was addressing exactly my problem. If anyone can offer advice, I would appreciate it.
Brian Wilkins
Offline
Re: php session dying when opening articles
Wich page(see page tab) uses article to be displayed? the same as other blog pages pages
Give a link to you site!
Offline
#3 2007-05-14 15:15:17
- bsw1971
- New Member
- Registered: 2007-05-14
- Posts: 4
Re: php session dying when opening articles
The blog is a new implementation to the overall site. The default page template is used for the first page of the blog, which is the same as the default install of TP. The article “First Post,” which is part of the TP install, uses the archive template. Other than adding the layout elements (my divs and css), I did not change any of the TP tags. I did add the code mentioned in my first post for the php session.
Due to a signed non-disclosure agreement, I’m unable to give you access to the site. I’m just hoping that someone might have some ideas that I could investigate.
Edit: Just to add to the strangeness, I can view the article in IE7, but I’m losing the session in Firefox (Windows and Mac) and Safari (Mac).
Edit 2: I used a Firefox plugin to read the HTTP Headers. Every time I try to access the article, the PHPSESSID is reset. I can’t see where any other pages are being referenced that would cause that, so does it have something to do with the fact that URLs are being “prettied-up” for user- and browser-friendly URLs?
Last edited by bsw1971 (2007-05-14 16:54:42)
Offline
#4 2007-05-15 00:32:10
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: php session dying when opening articles
Your session settings probably aren’t correct. Blindly calling session_start() isn’t sufficient.
Alex
Offline
#5 2007-05-15 00:37:25
- bsw1971
- New Member
- Registered: 2007-05-14
- Posts: 4
Re: php session dying when opening articles
Can you point me to something that might explain better what to do? All of the books and web sites I’ve looked at do it that way, so I’m not sure of any other way.
Offline
#6 2007-05-15 04:24:53
- bsw1971
- New Member
- Registered: 2007-05-14
- Posts: 4
Re: php session dying when opening articles
This was driving me crazy, but I’ve finally figured out what is happening, but I’m not sure why. Sorry I can’t give the address out because the site is a prototype and I’ve signed a non-disclosure agreement. I would type in the URL example.com, I would enter my user name and password, and browse the site. When I clicked on the blog link it took me to the main blog page, but clicking any of the other links to blog articles wouldn’t work. After using the LiveHTTPHeaders plugin for Firefox, I saw that the PHPSESSID was changing every time I accessed the blog. However it worked on other computers no problem. Come to find out if I entered the URL with www.example.com (notice the www) everything worked perfectly and the sessions never reset. I’m new to Textpattern, but I think when Textpattern calls css.php it’s using the entire URL www.example.com which is causing the session to reset if I started browsing the site using the URL example.com.
Is this typical of sessions?
Offline
#7 2007-05-15 04:35:39
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: php session dying when opening articles
PHP session docs. There are any number of ways of misconfiguring or breaking sessions. Yours is one of them.
Alex
Offline
#8 2007-05-15 07:12:40
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: php session dying when opening articles
I work around problems like this by forcing one or the other format (with or without www). I personally prefer without www, since it’s unnecessary.
<IfModule mod_rewrite.c>
RewriteEngine on
# no www ------------------
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
</IfModule mod_rewrite.c>
The above automatically redirects people to the non-www version of any given url for my blog (I place it before my Txp rewrite rules).
Last edited by Mary (2013-01-24 17:15:45)
Offline