Passing Cookie to an Include file HELP!!!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

astro_sk
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Oct 13, 2002 5:00 pm
Location: Brasil

Passing Cookie to an Include file HELP!!!

Postby astro_sk » Mon Sep 08, 2003 8:01 am

basically I have a folder with several pages and a cookie is set before you can view any of them. this cookie works wonderfully on all pages untill I try to check the cookie within an include file

the include file (menu.php) basically looks like this:

Code: Select all


<?php
if ($_COOKIE['AccessSciencesAdmin']) { ?>
listone <br>
listtwo<br>}
else{
sorry no listing available
}



the file that I am including it in has the following code:

Code: Select all

<?php
    require "checkcookie.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><body>
<?php
include ('menu.php');


</body>




the checkcookie.php works beautifully on all pages it basically checks to see if the user has the correct cookie with this:

Code: Select all

<?
if (empty($_COOKIE['mycookie'])) {
    $message = 'Your login has expired, please login again';
    #header('Status: 302 Moved Temporarily');
    header("Location: admin/index.php?message=" . urlencode($message));
    exit(0);
} else {
    setcookie('mycookie', '1',0,'/');
}
?>


I have looked every where to try and find out why the cookie seems to disapear in include files any where in any Directory?????

any Ideas??

Any one?

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Mon Sep 08, 2003 12:17 pm

i didnt understud you. exlain more please...

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Cookie Problem

Postby ruturajv » Mon Sep 08, 2003 10:39 pm

Hi,
First I must applaud you for writing a very neat Post with neat spaces and easy on the eye. :D :D Swirlee isn't this the kind of post we should be seeing more often??

For your question,
Check what path is set for the cookie. If the page where you are including the checkcookie.php is not in the path, cookie won't work.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Sep 09, 2003 11:06 am

huh... i am to old for such thing.

P.S.
I am go to learn English =)...

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: Cookie Problem

Postby swirlee » Tue Sep 09, 2003 1:56 pm

ruturajv wrote:Swirlee isn't this the kind of post we should be seeing more often??


Agreed. I just wish I knew the answer to his question. :D

astro_sk
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Oct 13, 2002 5:00 pm
Location: Brasil

Postby astro_sk » Tue Sep 09, 2003 2:43 pm

thanks for the suggestion but that doesn't seem to matter as I have placed the file in the directory the cookie was created.

still nothing....

any other ideas???

thanx

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Re: Passing Cookie to an Include file HELP!!!

Postby ruturajv » Tue Sep 09, 2003 9:37 pm

astro_sk wrote:the checkcookie.php works beautifully on all pages it basically checks to see if the user has the correct cookie with this:


What do you mean it works with other pages? If it works with other pages, should'nt it work here as well

astro_sk
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Oct 13, 2002 5:00 pm
Location: Brasil

Postby astro_sk » Wed Sep 10, 2003 7:26 pm

found the problem it.

because I was using a full url to source to my include page, PHP was treating it as if it where from a completely different site, Therefore the cookies where of course not good for a different site, even though it was in the same directory.

see what I mean.

My original post should of been

include ($siteurl.'/menu.php');
sorry about that

so now it works using

include('../menu.php')


thank you all for your help


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest