Cookie not set in my application

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Cookie not set in my application

Post 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";
}
*********************************
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: Cookie not set in my application

Post 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
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post 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";
}
?>
Last edited by salehalatif on Tue Feb 17, 2009 11:24 pm, edited 1 time in total.
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: Cookie not set in my application

Post 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
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post by salehalatif »

which file you want?
i want to redirect it to Home.php
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: Cookie not set in my application

Post 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
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post 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!";
}
?>
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Cookie not set in my application

Post by papa »

Try session_start() in the beginning of your document.
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post 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.
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: Cookie not set in my application

Post 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
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post by salehalatif »

Yes cookie is set
but in application that error is still.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Cookie not set in my application

Post 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.
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: Cookie not set in my application

Post by jothirajan »

?????

What type of error you are getting
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post 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
salehalatif
Forum Newbie
Posts: 9
Joined: Wed Jan 28, 2009 12:03 am

Re: Cookie not set in my application

Post by salehalatif »

any idea?
Post Reply