473,666 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setcookie() returns true but no cookie appears.

7 New Member
I have two hosting accounts. On one, my setcookie script works fine; cookies are created. On the other, the same script doesn't work. The function returns TRUE, but no cookies is created.

I checked to make sure that the variables have values and that the proper expire time is set and etc.

Any ideas?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     foreach($_POST as $name => $value){
  3.         if($name == 'hItem'){
  4.             $item = $value;
  5.         }
  6.         else if($name == 'hPrice'){
  7.             $price = $value;
  8.         }
  9.         else if($name == 'hQuantity'){
  10.             $quantity = $value;
  11.         }
  12.         else if($name == 'wQuantity'){
  13.             $wantedQuantity = $value;
  14.         }    
  15.         else if($name == 'hImage'){
  16.             $image = $value;
  17.         }
  18.         else if($name == 'hShipping'){
  19.             $shipping = $value;
  20.         }
  21.         else if($name == 'hCategory'){
  22.             $category = $value;            
  23.         }                            
  24.     }
  25.  
  26.     if($quantity <= 0){
  27.         echo "This item is no longer available. Please select another item!";
  28.     }
  29.     else{
  30.         if($wantedQuantity > $quantity){
  31.             $wantedQuantity = $quantity;
  32.         }
  33.  
  34.         $i = 0;
  35.         while($i < 1000){
  36.             if(isset($_COOKIE['cItem' . $i])){
  37.                 if($_COOKIE['cItem' . $i] == $item){
  38.                     break;
  39.                 }
  40.             }
  41.             else
  42.                 break;
  43.             $i++;
  44.         }
  45.  
  46.         setcookie("cItem" . $i, $item, time() + 3600);
  47.         setcookie("cPrice" . $i, $price, time() + 3600);
  48.         setcookie("cQuantity" . $i, $wantedQuantity, time() + 3600);
  49.         setcookie("cImage" . $i, $image, time() + 3600);
  50.         setcookie("cShipping" . $i, $shipping, time() + 3600);
  51.         setcookie("cCategory" . $i, $category, time() + 3600);
  52.  
  53.         $link ="<script>document.location.href = 'viewcart_t.php'</script>";
  54.         echo $link;
  55.     }
  56. ?>
Sep 25 '08 #1
8 5865
Markus
6,050 Recognized Expert Expert
I'm sorry, I couldn't find a question in your post?
Sep 25 '08 #2
SupraFast
7 New Member
Question is, do you see anything wrong with my script that wouldn't create a cookie? As I said, the same exact script works on the other account. Same browser is used, IE7. Variables, Time, and return values are all good.

Could it possibly be a setting on the account or server that's preventing the cookie to be created?
Sep 25 '08 #3
Markus
6,050 Recognized Expert Expert
Question is, do you see anything wrong with my script that wouldn't create a cookie? As I said, the same exact script works on the other account. Same browser is used, IE7. Variables, Time, and return values are all good.

Could it possibly be a setting on the account or server that's preventing the cookie to be created?
Ah.

Well, if you're saying that the scripts is *exactly* the same and the only variable in this is the server it is hosted on, then, yes, it must be the server causing a problem.

Someone else may be able to shed some light on this.

Do the php versions on the servers differ?
Sep 25 '08 #4
Atli
5,058 Recognized Expert Expert
Hi.

Are there any differences in the two servers?
Different PHP versions or HTTP servers?
Are the URL's used by them different?

You could try setting the path and domain parameters of the setcookie function.

And just a suggestion.
You really should remove the JavaScript redirect in lines 53 and 54 and just set the Location header via the header function.
Expand|Select|Wrap|Line Numbers
  1. header("Location: viewcart_t.php");
Much cleaner and won't fail in browsers that don't allow JavaScript.
Sep 25 '08 #5
SupraFast
7 New Member
The server is the same and the accounts have the same settings. It seems the problems is fixed now.


This behaviour was very odd and maybe somebody can explain why.

1. I uploaded all the files from one domain to the other domain. The cookies worked on the orginal domain, but not the new one.
2. I tried clearing the cookies, temp internet files, closing browsers completley, and etc. Still didn't work on the other domain.
3. I then tried it in firefox. It worked in there oddly enough. It seems IE7 was giving an issue for the other domain...even though the same scripts worked from the other site in Firefox and IE lol.
4. I gave my computer a reboot and now everything works fine.

So, just out of curiosity, why would have one site worked in both browsers and not the other if they are the same files, same server, same account settings. Maybe some memory issue with IE7, not sure really.
Sep 26 '08 #6
Atli
5,058 Recognized Expert Expert
Sounds like a caching problem in IE. Maybe an identical set of cookies from another domain confused it or something.

Well it's IE... what do you expect :P

I'm pretty sure it's wasn't a problem with your server, seeing as it working in FF and then in IE once the client computer was rebooted.
Sep 26 '08 #7
SupraFast
7 New Member
Okay lol, I found the problem and I must apologize to IE7 lol.

Hopefully this will help other people down the road. I was looking more closely at my backup script and I now realize that the script was slight different.

I was using time() + 846400 on the old script and time() + 3600 on the script that had the problem.

Now the issue is, I didn't take into account that the server is located in PST and I'm in EST. Therefore 1 hour [3600] was not sutiable for a 3 hour time difference. I was basically setting the cookie to delete.

Why was it working when I rebooted? Well my PC is on it's last legs and I have to reboot it every 2 or 3 days. When I do, the time gets set back a few hours. So yeah lol. I'm glad I figured it all out though.

Thanks for helping guys. Sometimes it just helps to talk stuff out.
Sep 27 '08 #8
Atli
5,058 Recognized Expert Expert
Ahh ok. That I wouldn't have predicted :)

Glad you solved the problem tho.
Sep 27 '08 #9

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

Similar topics

1
2960
by: Phil Powell | last post by:
setcookie('nordicnet_registration', $uplinenumber); // SESSION COOKIE TO BE SET I have this cookie I have to set that will be session-based (cookie deletes when browser session is closed, the classic). However, the cookie is set in /Main_page/registrering.php so the path for the cookie is incorrect; I want the path to be '/'. HOWEVER, PHP is strict on syntax so that if I set a path, I have to set a time int value at the same time. I...
16
11302
by: Phil Powell | last post by:
Fourth attempt.. it fails now in login, I check by printing $_COOKIE and there is no value there! Guys, what on earth do I do about this???? Here is the code that sets the cookie: if ($hasLoggedIn && ($row = mysql_fetch_row($query))) { setcookie('nordicnet_registration', $row, 0, '/'); @mysql_free_result($query);
4
8172
by: Greg Bryant | last post by:
Wondering why my setcookies didn't have any impact, I noticed the line in the manual that said the page needs to be reloaded before they take effect (which does make a certain kind of sense). So, how do I force a page to reload? Thanks, Greg
3
8887
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
3
3402
by: RotterdamStudents | last post by:
For registering a user to one of my sportleagues i use a little part of undeneath script to set a cookie. but this returns the next fault when a new user registers: Warning: setcookie()expects parameter 2 to be string object given in *.php on line 21 21: while (!setcookie("USER",$User, time()+3600)) { 22: $errmsg = $Unable_to_register_txt; 23: LogMsg($errmsg);
6
2067
by: GregoryD | last post by:
I'm going to try to simplify this issue as much as possible. In my public_html/ directory, I have a login script that sets a cookie to be used for authentication purposes. To set the cookie, it has something like this: <?php setcookie('code',$value, time + $lifetime, '/', '.example.com'); ?>
3
2286
by: Cmaza | last post by:
Hi, I've been dealing with PHP for a few years now and I've never encountered a problem quite like this. I've searched the net for an answer to my problem hoping somebody else may have encountered this, but without any luck, so I now resolve to pose the question myself. Code: <?php $somedata="Lorem Ipsum";
9
2286
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000." 4. Display last modified date of doc. Here is my attempt. What a headache :-(
0
8443
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.