Session and cookies problem.

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
thenndral
Forum Newbie
Posts: 20
Joined: Wed Sep 29, 2010 8:36 pm

Session and cookies problem.

Post by thenndral »

Hello,

I have a problem in cookies setting.
let me explain my problem.

I want to store my login details in cookies.
I have a source for login page. this source from our another project source. I copied the same source and paste it on my current project. but my login page not set cookies, it return empty.

source same as previous project and login table also same.
difference is project name and DB name.

my question is, for my new project any setting have to do for cookies and sessions.
Any ideas or code help?

Thanks in advance,
thenndral
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Session and cookies problem.

Post by oscardog »

No, but you may have set the cookies to only affect a certain directory. Make sure the 4th parameter is set to '/'.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Session and cookies problem.

Post by social_experiment »

Can you paste the code used to set the cookie
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
thenndral
Forum Newbie
Posts: 20
Joined: Wed Sep 29, 2010 8:36 pm

Re: Session and cookies problem.

Post by thenndral »

Hello,

This is the same code work for another project but not working for my current project.

Here is my code.

Code: Select all

setrawcookie("id_Cookie", $req_Userid, 0, "/"); //set cookie with userid.
setrawcookie("Cookie_UName", $arr_userinfo['name'], 0, "/"); //set cookie with user name

include_once("../include/common_class.php");
include_once("../include/db_class_mysqli.php");

$req_Userid = $_POST["loginUserId"];
$req_Userpwd= $_POST["loginUserPwd"];


if ( $req_Userid && $req_Userpwd )
{
	$db = new DB_MYSQL();
	$returnValue = $db->isExistUserInfo($req_Userid,$req_Userpwd);

	if ( $returnValue )
	{
		$db = new DB_MYSQL();
		$arr_userinfo = $db->getSecurityLevel_DB($req_Userid);
		

if ( $db->getCount() < 1 ) {
	echo <<<__HTML__
	<script lang='javascript'>
		alert('Incorrect Login id!');
		history.go(-1);
	</script>
__HTML__;
}
	$userUid = ($arr_userinfo['uid']);
	$userName = ($arr_userinfo['name']);
		
	setcookie("id_Cookie", $req_Userid, 0, "/", $_SERVER['HTTP_HOST'], 0); //set cookie with userid.
	setcookie("Cookie_UName", $userName, 0, "/", $_SERVER['HTTP_HOST'], 0); //set cookie with user name
		
	echo <<<__HTML__
	<script language='javascript'>
		location.href = "/main.php";
	</script>
__HTML__;
	} else {
	echo <<<__HTML__
	<script language='javascript'>
		alert('Login Failed!');
		location.href = "index.html";
	</script>
__HTML__;
}
	}
	$db = null;


Thanks in advance,
thenndral
thenndral
Forum Newbie
Posts: 20
Joined: Wed Sep 29, 2010 8:36 pm

Re: Session and cookies problem.

Post by thenndral »

Hello,

No replies. Give some idea. It's Urgent.

thanks,
thenndral
Post Reply