Jump to content

Weird Cookie Problem


kev670

Recommended Posts

I have a very odd cookie problem that's hard to explain so please bare with me...

 

The first piece of code found below is the login process, where the login is checked and the cookie is created or not, the second piece of code below is a library which is called to display the login menu and get the connection to the database.

 

The problem I'm having is I cant put these 2 files in the same folder. The cookie gets created if i put the process login into a directory and the library into a sub directory called inc ... then i "include("inc/library.php");" in the login process. I then point the form for the login to http://www.alcaeos.com/blog/loginProcess.php...

 

If I do these 2 things then the cookie is created but if I place both files in the inc folder (The code below is the example of when both files are IN the inc folder) then the cookie does not get created. the login system still works and tells the user if they successfully logged in or not, it just wont create the cookie... It's an odd problem I think. Has anybody got any ideas... Thanks

 

 


<?php


include("library.php");



connectToDatabase();


$username = $_GET['username']; 
$password = $_GET['password'];

$sql = "SELECT * FROM theUsers WHERE user = '$username' AND pass = '$password';";

$result = mysql_query($sql) or die(mysql_error());  

if ($obj = mysql_fetch_object($result)) 
{
$expire=time()+60*60*24*30;	
setcookie("shopusername",$username,$expire);					
echo "<A HREF='http://www.alcaeos.com/blog/test.php'>You are logged in</A>";

}

else
{
loginScreen();
echo "You are NOT Logged In";
}	

$db->close();

?>


<?php 

function loginScreen()
{

$output = <<<LOGIN

	<FORM method ="GET" action="http://www.alcaeos.com/blog/loginProcess.php">
		<table>
		<tr>
			<td>Username: </td>
			<td><INPUT TYPE = "text" NAME = "username"></td>
		</tr>
		<tr>
			<td>Password: </td>
			<td><INPUT TYPE = "password" NAME = "password"></td>
		</tr>
		</table>

	<INPUT TYPE="submit">
	</FORM>

LOGIN;

echo $output;
}

function connectToDatabase()	
{
$dbhost = 'mysql*******';
$dbuser = 'kem*******';
$dbpass = 'ya****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

$dbname = 'ke********';
mysql_select_db($dbname); 
}

 

 

 

Link to comment
Share on other sites

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.