Jump to content

Login Form Issue


Zola

Recommended Posts

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! :)

Link to comment
Share on other sites

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 by PFMaBiSmAd
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.