Zola Posted November 5, 2012 Share Posted November 5, 2012 Hi all I have an issue I can't quite figure out... I have a login section for members of a site...The login form directs the user to a directory with member files etc. If the user name or password is wrong, it will divert to a failed log in page. I have tested this among a lot of browsers and it works in all if www. is included in the address bar in the web address. Without the www., the users have to log in twice, or else not at all to get in... Any idea what I can do to fix this? Here is the php code for the headers etc: <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { $_SESSION['name'] = true; header("Location: http://www.mysite.com/download/index.php?un=$name"); exit; } else { header("Location: http://www.mysite.com/failed_login.php"); exit; } } } if(!isset($_SESSION['name'])) { header("Location: http://www.mysite.com/register.php"); } ?> Any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/270322-login-form-issue/ Share on other sites More sharing options...
Muddy_Funster Posted November 5, 2012 Share Posted November 5, 2012 this isn't a php issue, it's a dns one. Quote Link to comment https://forums.phpfreaks.com/topic/270322-login-form-issue/#findComment-1390366 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2012 Share Posted November 5, 2012 (edited) The problem is because cookies (the session id cookie in this case) are by default specific to the variation of the domain where they were created at. Because you are not setting the session id cookie domain setting to match all variations (with and without www.) of your domain, it only matches the variation where it was set at. A) You should be constant in your use of www or no www on your domain/links, B) You can redirect all non-www requests to the www version of your domain in a .htaccess file. C) You can set the session id cookie domain to be .yourdomain.com (with the leading dot.) See this link - session_set_cookie_params Edited November 5, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/270322-login-form-issue/#findComment-1390370 Share on other sites More sharing options...
Zola Posted November 16, 2012 Author Share Posted November 16, 2012 Sorry for the late reply! I got this sorted with HTaccess. I found the code on this website: http://dense13.com/blog/2008/02/27/redirecting-non-www-to-www-with-htaccess/ Thanks very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/270322-login-form-issue/#findComment-1392906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.