passing cookie variables

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
davidpiter98
Forum Newbie
Posts: 1
Joined: Thu Apr 12, 2018 11:28 pm

passing cookie variables

Post by davidpiter98 »

Hi guys,

An authentication script which then extracts the user id entered by the user and then stores it in a cookie variable called $mycookie.

Further on into the site I am able to use the cookie to perform various select statements. Only problem is that php files that i have 'required' do not recieve or even recognise the $mycookie variable.

example: require("add.php");

So my select statements which end WHERE user_id='mycookie' simply do not function.

Please forgive me if im overlooking something very small, please point me in the right direction.

Many thanks.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: passing cookie variables

Post by Vegan »

usually cookies are done with JavaScript which then calls some PHP code on the web server to update the database that a cookie has been set etc

you will discover that there is a lot of interaction back and forth with PHP and JS
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: passing cookie variables

Post by Christopher »

Read the manual about cookies: http://php.net/manual/en/features.cookies.php

Get cookie values in PHP from the $_COOKIE global. Use the setcookie() and setrawcookie() functions to set cookies.
(#10850)
Post Reply