Jump to content
xisto Community
Sign in to follow this  
who?

Blank Cookies... Need some help with Cookies...

Recommended Posts

Hi. I'm doing a website that basically checks if it has chosen a css style before. If it has, it shows the last shown style, and if it doesn't, it shows "natura" style. On the page there's a form that lets the user choose the style. It is based on cookies. The thing is that when I do java script:alert(document.cookie) on the address bar it gives me a blank alert! And, obviously, when I reload the page, the style doesn't change!!! The thing is I'm sure it has nothing to do with the HTML code, and I also thing it does have nothing to do with the php code neither, because the whole script works on localhost. Here is the php code:

<?php$arrColorAds = array("plain"=>"6699CC", "natura"=>"FFFFFF");if(isset($_POST['style'])) {	$style = $_POST['style'];	$colorAds = $arrColorAds[$style];	setcookie("style", $style, time()+2678400);} elseif(isset($_COOKIE['style'])) {	$style = $_COOKIE['style'];	$colorAds = $arrColorAds[$style];	setcookie("style", $style, time()+2678400);} else {	$style = "natura";	$colorAds = $arrColorAds[$style];	setcookie("style", $style, time()+2678400);};?>HTML code...

Please help me! This is for a school project, so I need to do this so I can focus on the real work!

P.S.: Off-topic: Does Xisto supports non-english sites? It used to not support them, that's why I'm asking.
And sorry for my English!!!

Share this post


Link to post
Share on other sites

Hi. I'm doing a website that basically checks if it has chosen a css style before. If it has, it shows the last shown style, and if it doesn't, it shows "natura" style. On the page there's a form that lets the user choose the style. It is based on cookies. The thing is that when I do java script:alert(document.cookie) on the address bar it gives me a blank alert! And, obviously, when I reload the page, the style doesn't change!!! The thing is I'm sure it has nothing to do with the HTML code, and I also thing it does have nothing to do with the php code neither, because the whole script works on localhost. Here is the php code:
Please help me! This is for a school project, so I need to do this so I can focus on the real work!


Hmm well I sure don't see anything wrong with it. Are you sure you are posting the style under the post variable "style"? It looks like its passing the first if statement or something. Try echoing "test" after your first setCookie(). If it doesn't print then thats your problem but if it does... hmm I have no idea. Post back here and tell us what happens.

P.S.: Off-topic: Does Xisto supports non-english sites? It used to not support them, that's why I'm asking.And sorry for my English!!!

About your question whether Xisto allows non-english sites: Basically no. Your site must be in english but you can get past that rule by having an english translation and a different language translation of your site.

Share this post


Link to post
Share on other sites

Hmm well I sure don't see anything wrong with it. Are you sure you are posting the style under the post variable "style"? It looks like its passing the first if statement or something. Try echoing "test" after your first setCookie(). If it doesn't print then thats your problem but if it does... hmm I have no idea. Post back here and tell us what happens.

I really don't understand what's wrong... Currently I'm using Javascript to do the job while I don't fix the PHP problem but I'm still looking for a solution. Thanks for your reply!
EDIT: "I already did two test pages: cookie1 and cookie2. Cookie1 was the cookie set script and Cookie2 was the reader. Nothing." => Forget this sentence... I just did the cookie1 and cookie2 thing again... It worked!!! So... I'm gonna analyze my if condition and what I've done wrong... It's weird the test didn't work the other time. It echoes nothing, so... Something's wrong. I'll see what I can find.
Edited by who? (see edit history)

Share this post


Link to post
Share on other sites

If it is echoing nothing that means that when you coded the forum for setting the style you didn't name the input correctly, or you are submitting it via get. Can you link us to your website? I might be able to help more that way.

Share this post


Link to post
Share on other sites

FIXED (BUT NOT FIXED)!!!

If it is echoing nothing that means that when you coded the forum for setting the style you didn't name the input correctly, or you are submitting it via get. Can you link us to your website? I might be able to help more that way.

Hi.No, I did named the input correctly, and I'm submitting it via post. (I would have noticed it, since I'm reviewing the code over and over!!! But thanks for your reply! You'll find the solution pretty stupid (or you'll think I'm a noob, because it maybe obvious to you and not to me)).

And the link is: http://forums.xisto.com/no_longer_exists/ (I forgot to mention it, sorry! But the code was the displayed one, except for the vars names, that are portuguese; nothing relevant...)

THE SOLUTION HAS BEEN FOUND:
Thank you for all your replies... After much testing pages and stuff... And after writing many lines of code... I found the solution... by accident! I use Dreamweaver to program my websites... Since (I think) CS3, Dreamweaver doesn't write entities on the code, because it uses UTF-8, which doesn't need entities, because it shows them correctly... I used to use Notepad to write small amounts of code... But since it was a big site... I used, once again, Dreamweaver... One of the test pages I did, I wrote it on Notepad... And it worked! I didn't know why at that time... I mean... I wrote a different code... A simpler code... So I compared them over and over again... Nothing was different (except for the name of the cookie and for the value var)... When I saved the same code with Dreamweaver... It didn't work! So... after much thinking... I realized it had to do with the UTF-8/ANSI (predifined in Notepad) situation...
Conclusion: It works when I resave the code in Notepad (using ANSI)... But I have to manually replace the entities... Why doesn't the code work in UTF-8? (By the way, the thing that doesn't work is the setcookie() function, because everything else in the PHP works, otherwise the $style var would come out blank, showing a stylesheet-less page.) Am I a really big noob? Or is this just stupid???
By the way, thank you very much for your replies!

EDIT:
After googling it... Got to a page that I've, during this problem, dozens of times (to verify everything was fine with my coding...): http://php.net/manual/en/function.setcookie.php. Somehow I didn't read that note, that says the same thing I concluded, so... For everyone that maybe reading this post in hope to find the answer to your setcookie() problem, here it is...
Edited by who? (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.