linein designs

29 Jan, 2007

PHP Header Redirect & Sessions Fix

Posted by: john In: apache| programing

One of the sites that I’ve been working on recently for some odd reason would not log users in (or at least not constantly). After looking into it further, I realized it had to do with the PHP function “header” redirecting the user if the login query was successfully.

The problem came when a user came to the site without typing in “www”. The page was redirecting to the site WITH the “www” and the $_SESSION vars were not getting set.

So to force every page to include the “www”, I added the following 3 lines to the .htaccess file and everything seems to be working fine.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]

Similar Posts:

No related posts.

1 Comment »

Comment by Jeff

Thanks! This was a huge help. Should have figured this one out on my own though!

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post



Please Support Our Sponsors

A Payday advance can be a great way to get back on track.

Banner

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.