Login and cookies sql connection db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
valmerin
Forum Newbie
Posts: 6
Joined: Mon Nov 02, 2009 5:29 pm

Login and cookies sql connection db

Post by valmerin »

Ok I have made a login script in a php file. When the user submits there info Name and Pass it gets sent to the script.

Code: Select all

<?php
ob_start();
include 'decl.php';
$user_session; //Is session exist
//Connection Info for databse
$con_host = "localhost";
$con_user = "root";
$con_pass = "google123";
$con_data = "pmv_data";
$user_db = "pmv_users";
mysql_connect("$con_host", "$con_user", "$con_pass") or die("can not connect to db");
mysql_select_db("$con_data") or die("Can not connect to table");
$user_name = $_POST['xuser_name'];
$user_pass = $_POST['xuser_pass'];
$user_name = stripslashes($user_name);
$user_pass = stripslashes($user_pass);
$user_name = mysql_escape_string($user_name);
$user_pass = mysql_escape_string($user_pass);
$sql = "SELECT * FROM $user_db WHERE user_username='.$user_name.' and user_password='.$user_pass.'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if ($count == 1) {
    $keep_user = $user_name;
    setcookie("pmv_user", $_POST['xuser_name'], time() + 60 * 60 * 24 * 100, '/', 'www.pmvbid.com');
    setcookie("pmv_userp", $_POST['xuser_pass'], time() + 60 * 60 * 24 * 100, '/', 'www.pmvbid.com');
} else {
    setcookie('pmv_user', $user_name, FALSE, '/', 'www.pmvbid.com');
    setcookie('pmv_userp', $user_name, FALSE, '/', 'www.pmvbid.com');
}
//header("location:../log.php");
print_r($_COOKIE);
ob_end_flush();
?>
 
But when i go to view the cookie on the main page after login it is not set.
Yes i know i have the redirect commented off that was so i can see if it is being written.
When it print_r the cookies i get this message

Array ( [pmv_user] => user_name [pmv_userp] => user_pass [PHPSESSID] => ri87h9h590dj40snal7asnn1f1 )

To me that is just putting user_name as user_name and user_pass as user_pass into the cookie but that's not right. Any Idea of why this is happening.

and cookies are enabled on all my browsers , Netscape, FF, IE, Chrome, and Safari.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Login and cookies sql connection db

Post by Mirge »

You really shouldn't include your actual ROOT mysql login information..
Post Reply