Current location: Hot Scripts Forums » Programming Languages » PHP » Problem with PHP cookies


Problem with PHP cookies

Reply
  #1 (permalink)  
Old 05-17-04, 04:37 AM
robii1 robii1 is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with PHP cookies

This is the first time I've tried to use PHP cookies so I'm stuck and don't have any idea what the problem is

I have tried to set a cookie on the following page: www.formymobile.co.uk/test2100fascias.shtml

The code looks like this:

<?php
setcookie("fasciaoffer", $name, time()+36000);
?>
<html>

I have checked & this does set a cookie on my pc

I then want to retrieve the cookie when my customer views their shopping basket and display a message

The code in my shopping basket is:

<?php
if (isset($_COOKIE["fasciaoffer"]))
echo "<b>Special offers available</b> - buy any 3 covers & get your 4th choice free! " . $_COOKIE["fasciaoffer"] . "!<br />";
else
echo "<b>Special offers available</b> - none available on current order<br />";
?>

The problem is as follows - even though I have the cookie on my pc, the message that comes up in my shopping basket is the one where the cookie has not be found

Anybody have any ideas about what the problem could be? Is my coding correct?

Also, I don't know if this makes any difference, but the file which the retrieve bit is in (the shopping basket) is not in the root folder

Thanks

Robert
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-17-04, 09:55 AM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
hi,

a cookie really holds info like passwords or broswser i dont think u need a cookie for what you want to do.
__________________
Elite Bulletin Board
http://elite-board.us
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-17-04, 10:12 AM
robii1 robii1 is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ok, I'm welcome to suggestions if you don't think a cookie would be best but if I can get the cookie to work if would do exactly what I wanted it to do so if you know what's wrong with the code that would also be useful
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-17-04, 10:33 AM
Trevor's Avatar
Trevor Trevor is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Denver, Colorado
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by robii1
This is the first time I've tried to use PHP cookies so I'm stuck and don't have any idea what the problem is

I have tried to set a cookie on the following page: www.formymobile.co.uk/test2100fascias.shtml

The code looks like this:

<?php
setcookie("fasciaoffer", $name, time()+36000);
?>
<html>

I have checked & this does set a cookie on my pc

I then want to retrieve the cookie when my customer views their shopping basket and display a message

The code in my shopping basket is:

<?php
if (isset($_COOKIE["fasciaoffer"]))
echo "<b>Special offers available</b> - buy any 3 covers & get your 4th choice free! " . $_COOKIE["fasciaoffer"] . "!<br />";
else
echo "<b>Special offers available</b> - none available on current order<br />";
?>

The problem is as follows - even though I have the cookie on my pc, the message that comes up in my shopping basket is the one where the cookie has not be found

Anybody have any ideas about what the problem could be? Is my coding correct?

Also, I don't know if this makes any difference, but the file which the retrieve bit is in (the shopping basket) is not in the root folder

Thanks

Robert
I've always had an interesting time when working with cookies. But here are my thoughts :

1) Are you sure $name is passing a value? To check this, echo out $name after you place your cookie. I usually test my vars with echo("name : $name<br>"); just to make sure that my head and PHP are on the same page. If you recieve a null value, there is your problem.

2) I usually find it benefitial to do a page refresh before reading in any cookies. Though you should put a qualifier like if (!isset($_COOKIE['fasciaoffer'])) { set cookie code }

I hope that helps.
__________________
The Universe Our God, Nature Our Temple, Love And Duty Our Religion, Knowledge Our Happiness And Consolation, Death The Dissolution Of The Ego, And The Return To Eternity.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-18-04, 05:00 PM
robii1 robii1 is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
it doesn't seem to be passing a value. so what could that be down to?

robert
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone help with htaccess and php problem tigherrdk PHP 6 03-09-09 03:28 AM
php in linux problem usman PHP 6 05-15-04 12:57 PM
Setting COOKIES problem.... ArksI PHP 4 04-05-04 04:00 AM
problem with PHP script on qmail server localrec PHP 2 03-25-04 02:49 PM
Javascript vs PHP, problem with arrays Chuff JavaScript 0 10-03-03 05:01 AM


All times are GMT -5. The time now is 08:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.