Page 1 of 2

Cookie not set in my application

Posted: Wed Jan 28, 2009 12:09 am
by salehalatif
Hello every1!
plz tell me why the cookie in my application is not set.

********LoginAction.php Code:********
ini_set("session.cookie_domain", ".myapp.com");

$EncUID = md5($ffUID);
if ($User[Type] == "CUST") {
setcookie("vplc", $EncUID, time()+3600, '/', '.myapp.com');
$RedirectTo = "http://www.myapp.com/Home.php?aaaa=$EncUID";
}
*********************************

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 12:30 am
by jothirajan
Just try this

if ($User[Type] == "CUST")
{
session_register("CUST");
$_SESSION['CUST']=$User[Type] ;
header("location:index.php") //// or something you want to have .......
}

Next go to that redirected page index.php

and print the $_session print_r($_session) ...there you can find the session.

Thanks
JOE....get me..if you want more to share

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 1:02 am
by salehalatif
jothirajan thank you for you help
but its still the same error.
i have security.inc.php file, which when adding your code i disabled
**********security.inc.php**********
<?php
ob_start();

// include files
ini_set("session.cookie_domain", ".myapp.net");
// intances of include files

$qryUID = $_REQUEST['aa'];
if($qryUID == '' && isset($_COOKIE['vplc']))
$qryUID = $_COOKIE["vplc"];
else
setcookie('vplc', $qryUID,time()+3600 );
$UID = $myUser->getUIDByEncUID($qryUID) ; // GET USER UID LIKE '20022'
$UserInfo = $myUser->getUserInfo($UID); // GET USER UID LIKE '20022'
$OID = $UserInfo[UID];
if ($UserInfo[UID] =="")
{
echo "Session expire";
}
?>

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 1:22 am
by jothirajan
can you give me your php file and the page you want to redirect?...

I will review and sort the issues...here in this content i cant clearly get you...

Thanks
JOE

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 3:36 am
by salehalatif
which file you want?
i want to redirect it to Home.php

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 3:46 am
by jothirajan
follow this

>>> just leave the php file you have

1) set the session name
2) if (condition=="ok")
{
set session;
and redirect;
}
3) go to the redirected page
print the session >> to check whether the session appears or not

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 4:39 am
by salehalatif
i put this code in a file cookie.php & excute it. Result: No Cookie Created!
This code is correct ??

<?php
// set the cookies
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");

// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
echo "$name : $value <br />\n";
}
}

else
{
echo "No Cookie Created!";
}
?>

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 4:46 am
by papa
Try session_start() in the beginning of your document.

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 4:47 am
by salehalatif
for Session:

********session.php*******
<?php
session_start();
$_SESSION['views'] = 1; // store session data
echo "Pageviews = ". $_SESSION['views']; //retrieve data
?>

Result:
PageViews= 1

means session is created.

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 4:59 am
by jothirajan
Yes this is correct.

So you can set the session

<?php
session_start();
$_SESSION['views'] = 1; // store session data
//echo "Pageviews = ". $_SESSION['views']; //retrieve data
print_r($_SESSION);
?>
will show the session Array ( [views] => 1 )

Then you can redirect to any other page and put the same print_r($_SESSION) in that particular redirected page, to find whether session have been set to that page.

Thanks
JOE

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 5:01 am
by salehalatif
Yes cookie is set
but in application that error is still.

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 5:03 am
by Benjamin
Ok seriously, everyone who has posted in this thread has not used the PHP code tags.

I would encourage all of you to review the forum guidelines.

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 5:08 am
by jothirajan
?????

What type of error you are getting

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 5:12 am
by salehalatif
@astions -> Sorry

@jothirajan -> Error "Cookie Not Created ";
But it redirect to Home.php with uid value
but when i click to further pages it & show an ERROR:
Either your session has expired |OR| you are not logged in

Re: Cookie not set in my application

Posted: Wed Jan 28, 2009 6:10 am
by salehalatif
any idea?