Jul 24, 2008

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

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

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

who?
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:

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 Trap17 supports non-english sites? It used to not support them, that's why I'm asking.
And sorry for my English!!!

 

 

 


Reply

galexcd
QUOTE(who? @ Nov 11 2007, 06:05 PM) *
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.

QUOTE(who? @ Nov 11 2007, 06:05 PM) *
P.S.: Off-topic: Does Trap17 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 trap17 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.

 

 

 


Reply

who?
QUOTE(alex7h3pr0gr4m3r @ Nov 13 2007, 04:14 PM) *
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.

Reply

galexcd
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.

Reply

who?
FIXED (BUT NOT FIXED)!!!
QUOTE(alex7h3pr0gr4m3r @ Nov 13 2007, 06:26 PM) *
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://alertaterra.freeweb7.com/ (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://www.php.net/manual/en/function.setcookie.php#78833. 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...

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : blank cookies cookies

  1. Making Sure They Did Not Leave Any Required Fields Blank - (3)
  2. Blank/duplicate Entries - a little help please. (5)
    Hi, I have been working with a download/link exchange script:
    http://evilddl.info/download/EViLDDL_1.0.1.rar However it has some problems when adding download
    links.. Users can submit downloads with no title, and also entries with duplicate titles. Can
    anyone show me how to fix this?? Here is the submit page: "> "> ">


    Menu ...
  3. <?php ?> Get Search Results To Your Localhost - Simple way to get 100 results without allowing cookies (2)
    Ultimately simple script that allows you getting google search results to your localhost. This is
    the first part of the Crawler script i'm developing, and if you are interested in developing the
    script with me, IM me @icq328866661@msn/evil_matak/ a \hotmail-com. Here's the form
    part... QUOTE search.php QUOTE if (@$_POST ==""){ echo "What are you
    doing?"; } else{ $query =
    file_get_contents("http://www.google.com/search?q=".urlencode($_POST
    )."&num=100&hl=en&ie=UTF-8&filter=2"); //needs to be added with more queries �...
  4. Using Sessions Instead Of Cookies, Help Please - (1)
    This is a simple code to register and login.. this uses cookies.. i want to use sessions instead..
    can someone tell how i can do it ? config.php CODE <?    ob_start(); // allows you
    to use cookies    $conn =
    mysql_connect("localhost","USER","PASSWORD");   
    mysql_select_db(DATEBASE) or die(mysql_error());    //fill in the above
    lines where there are capital letters.    $logged = MYSQL_QUERY("SELECT * from users
    WHERE id='$_COOKIE[id]' AND password = '$...
  5. Sessions And Login - Without Cookies (5)
    Hi, I have a login script i made using PHP sessions and MySQL. It works fine but there is a
    problem. As you know Sessions are stored in Cookies by PHP. So if someone has switched Cookies off
    then no sessions will work. How to solve this problem ? Please help me. Thanks and have a good
    day. ...
  6. Cookies - How to make something like that? (1)
    Can anybody help me? Im making new website and there will be needed such thing as login... so there
    will be needed thing as cookies too. Can anybody please tell me how to make them and how and where
    to use them? Alredy thanks, Dawiss...
  7. Php Shows Blank Page - (1)
    Hey there everyone, I'm trying to create a website using some PHP. I created an order form for
    my school company to let people order products this way. Only orders are made - no payments or
    anything. Now I have create the whole website. It is very simple. Every different product has a
    different combobox to select the number of items from. Then on the end of the page the client's
    details are asked. Now I created this PHP file that would handle everything, that is collecting all
    information and creating a well-formatted e-mail to send to the company's e-mail a...
  8. Grrrr, Cookies Just Wont Work :( - (2)
    Ok i have tried many tutorials and all tell me to do this: setcookie("uname", $name,
    time()+36000); But it always says: "Warning: Cannot modify header information - headers already
    sent" They say to put it on the very first line with no spaces, which i do, like this: Im using
    IIS with XP Pro, and have PHP 4.3 installed... why wont it work? /sad.gif' border='0'
    style='vertical-align:middle' alt='sad.gif' /> **edit, wow i cant believe no one could answer this
    EASY question, but after reading many documents, i figured out that i hadent declared the $name...



Looking for blank, cookies, cookies,

Searching Video's for blank, cookies, cookies,
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE