Jump to content

sessions, cookies and subdirectories?


tjhilder

Recommended Posts

Sorry if there are currently loads of topics, I'm not sure what I'm looking for atm so pardon me if this is a repeat topic of some sort.

 

Right I haven't been doing web design for at least a couple years due to ill health so I probably had this solution before but it's gone right out of my head right now lol

 

this is my code, but i'm not sure if this is correct for the subdirectories that i've currently got it in.

 

		$query = "SELECT rank, username, member_id FROM members WHERE (username='$u' AND password='$p')";
	if($result = @mysql_query ($query))
	{
		list($rank, $username, $member_id) = mysql_fetch_array($result);

                        if($rank == '1')
                        {
			$redirect_url = $_POST['direction'];
        	                if(isset($_POST['v3_cookies']))
			{
  					setcookie('username', $username, time()+60*60*24*30, '/', 'website.com', 0);
				setcookie('member_id', $member_id, time()+60*60*24*30, '/', 'website.com', 0);
			}
			else
			{
				$_SESSION['username'] = $username;
				$_SESSION['member_id'] = $member_id;
			}
			mysql_free_result($result);

              			ob_end_clean(); // Delete the buffer.
			header("location: /index.php");
			exit();
		}
		else
		{
			echo "<font style=\"color : #F00; font-weight : bold;\">NOTE:</font> You do not have permission to Access the Administration Area.";
		}
	}
	else
	{
                        $info[] = 'The Username and Password entered do not match those on file.';
		$info2[] = '<br /><br />Error: ' . mysql_error() . '<br /><br />Query : ' . $query;
	}

 

what is the right way of putting this bit of code when it's in a few subdirectories?

 

  					setcookie('username', $username, time()+60*60*24*30, '/', 'website.com', 0);
				setcookie('member_id', $member_id, time()+60*60*24*30, '/', 'website.com', 0);

 

thanks very much for reading, as previously mentioned it's been a while since I've done this and i'm getting a bit of a headache right now so can't think straight  :'(

Link to comment
https://forums.phpfreaks.com/topic/166861-sessions-cookies-and-subdirectories/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.