473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading a cookie set in javascript with php

Khaiya
4
I'm trying to read a cookie that I set with javascript with php. I've tried many websites and nothing I've found works at ALL (except var_dump() printed up null) but other then that all I've gotten is a blank page.

Here is what I've tried...


(page1.php)
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. createCookie('name','jim',7)
  3.  
  4.  
  5. function createCookie(name,value,days) {
  6.     if (days) {
  7.         var date = new Date();
  8.         date.setTime(date.getTime()+(days*24*60*60*1000));
  9.         var expires = "; expires="+date.toGMTString();
  10.     }
  11.     else var expires = "";
  12.     document.cookie = name+"="+value+expires+"; path=/";
  13. }
  14. </script>
  15.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

(page2.php)
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $var1=$_COOKIE['name'];
  4.  
  5. echo $var1;
  6.  
  7.  
  8. ?>
  9.  
I've also tried...
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $var1=var_dump($_COOKIE['name']);
  4.  
  5. echo $var1;
  6.  
  7.  
  8. ?>
  9.  
but so far nothing has happened.
May 29 '07 #1
2 2427
pbmods
5,821 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. $var1=var_dump($_COOKIE['name']);
var_dump doesn't return anything. Instead, try this:

Expand|Select|Wrap|Line Numbers
  1. var_dump($_COOKIE);
  2.  
Check to make sure the domain and expiration date for your cookies are valid.
May 29 '07 #2
Khaiya
4
var_dump doesn't return anything. Instead, try this:

Expand|Select|Wrap|Line Numbers
  1. var_dump($_COOKIE);
  2.  
Check to make sure the domain and expiration date for your cookies are valid.

I've tried that now and it didn't work either, and I guess the main problem is that I only sort of know the domain and expiration date of my cookies, and I don't really understand what var_dump() even does...

I know that a cookie automatically attaches the domain that it was saved from to the cookie but when I call the cookie how do I specify the domain name it came from?
May 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ken | last post by:
I am new to PHP. But this seems like a terrific language. I have been using JavaScript up to now but it looks like I will be changing to PHP. Seems to have more potential. I am confused about...
1
by: Jack Whitton | last post by:
Hi Im creating a website at the minute and I need some help with the homepage. I want there to be 3 flags, English German and Spanish, and when a user clicks on there flag I want them to be...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
6
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My...
2
by: HopfZ | last post by:
Server sends cookie to browser and the browser send the same cookie back to the server according to Wikipedia. Do browsers send even javascript-generated cookie to servers? For example, if I...
29
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
8
by: LayneMitch via WebmasterKB.com | last post by:
I'm supposed to develop a page that asks info as form values and when you hit "submit" it takes you to a page that reads the values you entered into the first page and displays those values in a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.