cookie variables and included files

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
seveninstl
Forum Newbie
Posts: 4
Joined: Fri May 14, 2004 12:38 pm
Location: Kissimmee, FL

cookie variables and included files

Post by seveninstl »

Can anyone tell me why...

when a user logs into my site, a cookie is created that holds some info. The user is then taken to the default index page (index.php).

Some menu options on this page call the index.php page again, and pass variables via the URL query string. (index.php?action=sports)

Now index.php is still used to generate the menus, but action=sports causes a page to be included (<?php include ('http://www.domain.com/sports.php?cat=0'); ?>

Because the include has a query string on the URL, the http part is required, without it php tries to find a page named 'sports.php?cat=0' and not a page named 'sports.php' with a quiry string of 'cat=0.'

Okay, now the problem. Using the fully qualified URL (with the http part) the included page can not see the cookie. It treats the user as if they are not logged in... the index.php page still knows they are there, but the included page asks them to login.

- it is all under the same domain name.
- both pages are set to use the same cookie.

Can anyone suggest a work around? A different way to include the file? Anything else?

Thanks!
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Why not just do it like this:

Code: Select all

$cat = 0;
include 'sports.php';
sports.php will have access to ANY variables that have been set up until that point in your script, hence it will be able to recognise $cat.
Post Reply