calling all cookie problems that is

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

User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

calling all cookie problems that is

Post by cheatboy00 »

i'm tring to call up a cookie and dectect whats in it and if its users or watever then do this... but even tho i know the cookies are there its not calling up the right page... see in the header.php file i have this

Code: Select all

if ($page == 'login' && $ucp == 'user' OR isset ($logcbaa) == 'user'){
 include ("ucp.php");
}
to call the right control panel, for the type of user, and if they just come to the site and loggedin previously and never logged out then it should still have the cookies and log them in automaticly..... see the first part of the if statement is correct that works is the or.... that doesnt... does anyone know whats wrong
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Assuming $logcbaa is the cookie have you tried, $_COOKIE['logcbaa']?

Mac
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

nope that didnt work

see i know the cookies are on my computer buts its like its not finding them or somethign... am i doing somethign wrong when i set the cookies....

Code: Select all

setcookie ("idcbaa",$id,time()+604800);
   setcookie ("logcbaa",$stat,time()+604800);
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

maybe the cookie isnt lasting as long and its surpose to is the time right?........... its surpose to be a week
Elfstone
Forum Newbie
Posts: 21
Joined: Tue Jun 11, 2002 2:25 am
Location: NJ, USA

Post by Elfstone »

If you are using an include statement to include the file that has the code which checks the cookies, be sure to include using the path on the server as opposed to the URL.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

what?????

the code that checks teh cookies is on header.php which is included from the index2a.php file (the main one)

and i have no idea how to .... include using the path on the server as opposed to the URL. ???
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

well there is no error that shows up so i dont know exactly....

everythign works except for teh fact that my cookies are not functioning i set the cookie but i duno why its not being called up when i call it

the whole objective is to get it so that when you login.... it sets a cookie called cblog and it has your status for what user panel you get so if your status is just a user your only allowed certian things etc...

that works logging in works... but when you come back to the site or go to somewhere else on the site it doesnt show the control panel anymore.... it'll just show the login screen...

thats my whole problem...... erg... see what i do i use an if to check to see if the cookies set and get the cookie what is teh value of the cookie and if it matches one of the properties i ahve lined out (user... staff.... admin), then go to the one it matches but it doesnt....
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

i found the whole problem...

its not getting the cookies....

when i make it so that the cookie has to be there to show a control panel, nothign shows up. making the control panel show up is all up to the cookie

for some reason its not finding or getting the cookie...

well the cookies might not even be on my hard drive becasue i've tried searching for them but havent found them i set the dir on the cookie to "/" where would that be ... in the c:/ drive.. i duno
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To check what cookies your site has set do:

Code: Select all

echo '<pre>';
print_r($_COOKIE);
echo '</pre>';
Cookies are generally stored with your temporary internet files so check that folder.

Mac
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

.. this is what comes up when i do that

Array
(
[idcbaa] => 2
[logcbaa] => user
)



so does that mean inside the first cookie it has the value [idcbaa] => 2 like all together like that or it the [idcbaa] just the name and the value is whats after the => thing well if it is that means its setting the cookie right but its not picking it up in the if statement
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

i found my cookies their in the temporary internet file folder.. under a text file called cbaa..... it contains both cookies... so should i isset($cbaa) .. becasue they are both in that file?....
Elfstone
Forum Newbie
Posts: 21
Joined: Tue Jun 11, 2002 2:25 am
Location: NJ, USA

Post by Elfstone »

Clarification about my include comment.....if using the include function, be sure you are using a path(Something like /usrs/me/web/file.php) as opposed to a URL(http://www.site.com/file.php). I've found that if you do the latter, it will not work with cookies very well, for some reason.

Secondly, This code you posted in your first post could be the problem.

Code: Select all

if ($page == 'login' && $ucp == 'user' OR isset ($logcbaa) == 'user')&#123; 
include ("ucp.php"); 
&#125;
isset won't return 'user', only true or false. Could be your problem there.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

o.k. i got this code off of the php manual ... duno it still doesnt work... i changed the $logcbaa to $cbaa because i found that both of the cookies i set are in one file called cbaa.... this is makeing my head hurt

Code: Select all

if (isset($cbaa) && ($cbaa == "user"))&#123; 
   include ("ucp.php"); 
&#125;
Elfstone
Forum Newbie
Posts: 21
Joined: Tue Jun 11, 2002 2:25 am
Location: NJ, USA

Post by Elfstone »

One thing I just thought of, is..cookies can only be used either by files in the directory they were created in, or subdirectories from that directory. Make sure that's not the problem you are having.

If that isn't your problem, try making a blank page with only a simple code to echo out your cookie variable. That's the easiest way to tell wether it is setting them correctly or not.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

you mean like the file with the set cookie is in ..../cbaa/filename.php
so make sure when i call the cookie the file thats calling it in has to be the same .....

well all my files for my web page are in /cbaa/ except for the pics which are in /cbaa/pics/
Post Reply