arbitter Posted March 31, 2010 Share Posted March 31, 2010 I really feel like I'm spamming this forum, with my many questions. Though I've really searched this one out, and can't find the problem. Setting the cookie is no problem, I'll give you the files: cookie.php <?php include('header.php'); ?> <for action='cookie2.php' method='post'> <input type="radio" name="kleur" value="green" /> Groen <br /> <input type="radio" name="kleur" value="blue" /> Blauw <br /> <input type="submit" /> </form> </html> cookie2.php <?php $kleur = $_POST['kleur']; $expir = time()+ 60 * 60 * 24 * 60; setcookie("uploadskleur",$kleur,$expir); ?> This is all good, because when I check my browsers cookies I see the right value. Now when I retrieve the cookie data, all goes fine too! I fI echo the cookie, I get 'green' or 'blue'. Now, I want to implement this in a file, and here's the real problem: <?php include('../header.php'); $sort2 = $_GET["sort"]; $_SESSION["sort"] = $_GET["sort"]; $sort = $_SESSION["sort"]; $_SESSION["month"] = $_GET["month"]; if(isset($_COOKIE['uploadskleur'])){ $dekleuris = $_COOKIE['uploadskleur']; $kleurachtergond= $dekleuris;} else{ $kleurachtergrond = '#cdaae7';} $kleurletter = 'white'; ?> This "$kleurachtergrond" I will use later on in the page to show which items are active. So if there's no cookie set, no problem, the second "$kleurachtergrond" shows (it's a light-purple). But If my cookie is set, it is transparant. I've tried doing it with eg #111111 , I've tried with or without apostrophes, I've tried without the semilicons ( {}, and ofcourse then I wrote one single line after the if), I've tried many possibilities, and I can't seem to get to the solution... The if(isset[blabla)) works, because I've tried it with solely echoing the cookie and that worked.. This is my first cookie, so I was delighted that my browser got a cookie from my site, and I would be even more delighted if it worked! Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/ Share on other sites More sharing options...
the182guy Posted March 31, 2010 Share Posted March 31, 2010 Looks like you have typed the variable name wrong on this line: $kleurachtergond= $dekleuris; Should it be $kleurachtergrond like it is in the ELSE section? So the whole thing is include('../header.php'); $sort2 = $_GET["sort"]; $_SESSION["sort"] = $_GET["sort"]; $sort = $_SESSION["sort"]; $_SESSION["month"] = $_GET["month"]; if(isset($_COOKIE['uploadskleur'])) { $dekleuris = $_COOKIE['uploadskleur']; $kleurachtergrond= $dekleuris; } else { $kleurachtergrond = '#cdaae7'; } $kleurletter = 'white'; Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034887 Share on other sites More sharing options...
greatstar00 Posted March 31, 2010 Share Posted March 31, 2010 if you encounter this kind of problem try to debug the problem by print out the variables try to copy and paste the variable from the error line debugging is trying to look for value, if they are the proper value the best programmer is not coding, they are debuggers try to find out the run time problem, and solve them coding is simple, finding problem it complex, try to learn to be a debugger (tester) the main role of debugging is look for correct values in the variable, (use copy paste from error line, and echo that variable in php, echo all variable from that line) Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034900 Share on other sites More sharing options...
arbitter Posted March 31, 2010 Author Share Posted March 31, 2010 Oh my bad, I put in the wrong file here. <?php include('../header.php'); $sort2 = $_GET["sort"]; $_SESSION["sort"] = $_GET["sort"]; $sort = $_SESSION["sort"]; $_SESSION["month"] = $_GET["month"]; if(isset($_COOKIE['uploadskleur'])){ $dekleuris = $_COOKIE['uploadskleur']; $kleurachtergond= $dekleuris;} else{ $kleurachtergrond = '#cdaae7';} $kleurletter = 'white'; ?> SO no problem there I also see I mde a type in my <form>, but it is correct here. Sorry about that And at the last reply; this is weird, when i type if(isset($_COOKIE['uploadskleur'])){ $dekleuris = $_COOKIE['uploadskleur']; $kleurachtergond= 'white';} else{ $kleurachtergrond = '#cdaae7';} $kleurletter = 'white'; ?> The colour isn't white but it's also transparant... So I guess there's something wrong with my if and else... But what then? Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034902 Share on other sites More sharing options...
greatstar00 Posted March 31, 2010 Share Posted March 31, 2010 as he said, you made a typo Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034903 Share on other sites More sharing options...
the182guy Posted March 31, 2010 Share Posted March 31, 2010 Yes, there looks to be a typo still, look at the variable name $kleurachtergond should it be $kleurachtergrond Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034905 Share on other sites More sharing options...
arbitter Posted March 31, 2010 Author Share Posted March 31, 2010 Oh no I feel so stupid right now! I triplechecked all the variables, and still... Darn! Oh well, my bad guys, sorry for wasting your time, and thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034921 Share on other sites More sharing options...
ignace Posted March 31, 2010 Share Posted March 31, 2010 What the hell is this? $sort2 = $_GET["sort"]; $_SESSION["sort"] = $_GET["sort"]; $sort = $_SESSION["sort"]; Shorter and easier to read: $sort = $_SESSION["sort"] = $_GET["sort"]; The same goes for: $dekleuris = $_COOKIE['uploadskleur']; $kleurachtergond= $dekleuris; $kleurachtergond = $_COOKIE['uploadskleur']; PS I know about "copy-on-write" still doesn't mean it can't be clean. Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034932 Share on other sites More sharing options...
arbitter Posted March 31, 2010 Author Share Posted March 31, 2010 What the hell is this? $sort2 = $_GET["sort"]; $_SESSION["sort"] = $_GET["sort"]; $sort = $_SESSION["sort"]; Shorter and easier to read: $sort = $_SESSION["sort"] = $_GET["sort"]; The same goes for: $dekleuris = $_COOKIE['uploadskleur']; $kleurachtergond= $dekleuris; $kleurachtergond = $_COOKIE['uploadskleur']; PS I know about "copy-on-write" still doesn't mean it can't be clean. Yeah I know.. But I'm rescripting all my pages, and then I recode it all (check everything, see if I can shorten anthing, if something is useles, if something is missing, put it in a good lay-out,..) and then it should all be better Because that was written in the beginning days of my scripting and I wanted to be sure it worked, so using $_POST[] and $_GET[] made me feel more sure Quote Link to comment https://forums.phpfreaks.com/topic/197158-problem-with-cookies/#findComment-1034937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.