clown[NOR] Posted April 7, 2007 Share Posted April 7, 2007 First of all. Admin, you can delete my post named "setcookie()....." starting over here Now, over to the problem... I just dont understand why, but it just wont process this code: <?php if (isset($phps_sbname)) { # Processed OK if (isset($_COOKIE['sbname'])) { # Prosessed OK if ($_COOKIE['sbname'] != $phps_sbname) { # Processed FAIL #setcookie("sbname", '', time()-31536000); #setcookie("sburl", '', time()-31536000); #unset($_COOKIE['sbname']); #unset($_COOKIE['sburl']); echo "Cookie would be unset()"; } elseif ($_COOKIE['sbname'] == '') { #setcookie("sbname", '', time()-31536000); #setcookie("sburl", '', time()-31536000); #unset($_COOKIE['sbname']); #unset($_COOKIE['sburl']); echo "Cookie would be unset()"; } } if (!isset($_COOKIE['sbname'])) { #setcookie("sbname", $phps_sbname, time()+31536000); #if ($phps_sburl != '') { setcookie("sburl", $phps_sburl, time()+31536000); } echo "New cookie would have been set"; } } } ?> if you need more info, this is the whole code: <?php $phps_sbname = $_REQUEST['sbname']; $phps_sburl = $_REQUEST['sburl']; $phps_sbmessage = $_REQUEST['sbmsg']; if ($phps_sbname == '') { echo 'Please enter a name'; } elseif ($phps_sbmessage == '') { echo 'Please enter a message'; } else { if (isset($phps_sbname)) { if (isset($_COOKIE['sbname'])) { if ($_COOKIE['sbname'] != $phps_sbname) { #setcookie("sbname", '', time()-31536000); #setcookie("sburl", '', time()-31536000); #unset($_COOKIE['sbname']); #unset($_COOKIE['sburl']); echo "Cookie would be unset()"; } elseif ($_COOKIE['sbname'] == '') { #setcookie("sbname", '', time()-31536000); #setcookie("sburl", '', time()-31536000); #unset($_COOKIE['sbname']); #unset($_COOKIE['sburl']); echo "Cookie would be unset()"; } } if (!isset($_COOKIE['sbname'])) { #setcookie("sbname", $phps_sbname, time()+31536000); #if ($phps_sburl != '') { setcookie("sburl", $phps_sburl, time()+31536000); } echo "New cookie would have been set"; } } } if ($phps_sburl == '') { $phps_newshout = "\n<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td bgcolor=#FFFFFF><strong>" . $phps_sbname . ":</strong> " . $phps_sbmessage . "</td></tr><tr><td bgcolor=#999999 height=1></td></tr></table>"; } elseif ($phps_sburl != '') { $phps_newshout = "\n<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td bgcolor=#FFFFFF><strong><a href=" . $phps_sburl . " target=_blank>" . $phps_sbname . "</a>:</strong> " . $phps_sbmessage . "</td></tr><tr><td bgcolor=#999999 height=1></td></tr></table>"; } $phps_sbfh = fopen("file.txt", "ab"); fwrite($phps_sbfh,$phps_newshout); fclose($phps_sbfh); Header("Location: http://www.nstclan.com/phpschool/v1.1/index.php"); ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 7, 2007 Share Posted April 7, 2007 i have had a few problems with $_REQUEST, try $_GET or $_POST Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 the $_REQUEST is working fine here... the problem is that it just stops processing after if ($_COOKIE['sbname'] != $phps_sbname) { and skips everything that has to do with cookies and start again when it comes down to if ($phps_sburl == '') { then it finishes the script and adds the shout and everything like it should... it looks like it just ignores all of this: <?php if ($_COOKIE['sbname'] != $phps_sbname) { # Processed FAIL #setcookie("sbname", '', time()-31536000); #setcookie("sburl", '', time()-31536000); #unset($_COOKIE['sbname']); #unset($_COOKIE['sburl']); echo "Cookie would be unset()"; } elseif ($_COOKIE['sbname'] == '') { #setcookie("sbname", '', time()-31536000); #setcookie("sburl", '', time()-31536000); #unset($_COOKIE['sbname']); #unset($_COOKIE['sburl']); echo "Cookie would be unset()"; } } if (!isset($_COOKIE['sbname'])) { #setcookie("sbname", $phps_sbname, time()+31536000); #if ($phps_sburl != '') { setcookie("sburl", $phps_sburl, time()+31536000); } echo "New cookie would have been set"; }?> Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 somebody please i'm going bold over this one ??? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 7, 2007 Share Posted April 7, 2007 any weird characters in the $phps_sbname ? Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 no... when I try it the value of that is "Clown" Quote Link to comment Share on other sites More sharing options...
per1os Posted April 7, 2007 Share Posted April 7, 2007 try using trim on the phps_sbname value, sometimes extra spaces get thrown in there. Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 a shot in the dark from me... shall the trim look like this? $phps_sbname = trim($phps_sbname); thanks for all the help you guys are giving me.. really apreciate it =) Quote Link to comment Share on other sites More sharing options...
per1os Posted April 7, 2007 Share Posted April 7, 2007 Yep it should. Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 nope... still nothing... i even tried to change: if ($_COOKIE['sbname'] != $phps_sbname) { to if ($_COOKIE['sbname'] != "Clown") { and it still dont want to to continue the processing... i think the code hates me =) Quote Link to comment Share on other sites More sharing options...
per1os Posted April 7, 2007 Share Posted April 7, 2007 try print_r($_COOKIE) make sure the cookie was set. If it was not look at the setcookie function on www.php.net/setcookie Try setting the domain and path, that may be why. Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 this is what I in return when i added the print_r($_COOKIE): Array ( [sbname] => Clown [sburl] => http://www.phpschool.co.nr/ [phps_loginstate] => 1 [phps_loginuser] => ** [phpSESSID] => 4defbbb0767a4035b85bd3cc20f4a57e ) * = the username i use to login to my control panel =) (proud about that... have made a fully functional CPanel on my site) *EDIT* How do I know the path to where the cookie will be available? I also think it's weird I would ahve to do that, since I don't need to do that on the other cookies I've made... Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 Ok I added the cookie array to the "addshout" file and it returned: Array ( [sbname] => Clown [sburl] => http://www.phpschool.co.nr/ [phps_loginstate] => 1 [phps_loginuser] => clown [phpSESSID] => 4defbbb0767a4035b85bd3cc20f4a57e ) Doesn't it say that the cookies "sbname" & "sburl" was added? then I added the same array at the top of my index.php and it returned: phps_loginstate => 1 phps_loginuser => clown PHPSESSID => 4defbbb0767a4035b85bd3cc20f4a57e no info about the sb cookies... what's going on with my cookies? give me my cookies back! bad computer! Quote Link to comment Share on other sites More sharing options...
per1os Posted April 7, 2007 Share Posted April 7, 2007 Maybe try storing them in session instead of cookies? Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Author Share Posted April 7, 2007 shit...that means i have to learn something new... hehe... think that will have to wait... 7.26am here now, havent been sleeping for about 17-18 hours .. hehe... been reading and studying php for all those hours =) fixing my CPanel... just figured out like 30 mins ago how to delete news, shouts and blog posts from the CPanel... gonna read about sessions tomorrow after we've been visiting my fiance's parents... Quote Link to comment 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.