Avatar of Sheldon Livingston
Sheldon LivingstonFlag for United States of America

asked on 

PHP cookies

Simply trying to set a cookie that can be read across my website.

/login/login.php sets a cookie using this code (using PHP):
setcookie("isLoggedIn","y");

This cookie can be seen from:
/login/loggedIn.php

But not from:
/index.php or
/see.php or
/contactUs/contactUs.php etc.

It can only be seen from /login/*

I assume that this can be done... any thoughts?
PHPHTML

Avatar of undefined
Last Comment
Sheldon Livingston
ASKER CERTIFIED SOLUTION
Avatar of msifox
msifox
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of msifox
msifox
Flag of Germany image

P.S. just setting IsLoggedIn provides very low security, because anyone can set such a cookie in his web browser. Better set it to a random number and store that random number also in $_SESSION. Then to check the state, compare both numbers.
Avatar of Sheldon Livingston

ASKER

Does the time=0 make it expire after the browser closes?
Avatar of msifox
msifox
Flag of Germany image

Yes, time 0 means the browser keeps it until the browser is closed. Another option is time()+3600 which will make it valid for one hour, time()+24*3600 for one day.
Avatar of Sheldon Livingston

ASKER

Thank you!
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo