antonyfal Posted August 31, 2011 Share Posted August 31, 2011 Hi a get a server error with this code, this worked for awhile, now it doesn't work. I use the first part to extract the user name from the url. then parse it to the IF cookie function as a variable for the cookie name. The cookie is placed on another html page and i placed it like this: <script language="javascript"> document.cookie = "{PROFILE_USERNAME}= 1"; </script> // this code works perfectly i used php to parser the variable to the javascript function, when i check the browser for cookies, it is placed correctly. this code i use to check the cookie's name to see if it exists. the variable below is taken from the url, and matches the username above, but when i execute the code i get this error: Illegal variable _files or _env or _get or _post or _cookie or _server or _session or globals passed to script. can anyone see the problem? <?php $url = $_SERVER['SCRIPT_FILENAME']; $newurl = explode("/", $url); $profmanager=$newurl[6]; $cook= $profmanager; if(!isset($_COOKIE['$cook'])) { $url2 = $_SERVER['HTTP_HOST']; $myurls = 'http://'.$url2.'/'; echo "<META HTTP-EQUIV=Refresh CONTENT=\"0;URL=$myurls\">"; } else { my page code here }?> // to note when i echo the $newurl[6] it does equal the username. the first code in on a html page/the javascript above, // the second code piece is AT THE TOP of a php page. // if there is a better way, liike matching values instead of the cookie name, i would be keen to see it in action. Quote Link to comment Share on other sites More sharing options...
spiderwell Posted August 31, 2011 Share Posted August 31, 2011 does this line need the single quotes? if(!isset($_COOKIE['$cook'])) Quote Link to comment Share on other sites More sharing options...
antonyfal Posted August 31, 2011 Author Share Posted August 31, 2011 Hi Spiderwell, I did try it with ["$cookie"] (double quotes) but that is when it began kicking the error, and everytime since. I did clear all my cache and ... I think it has something to do with the way i call the $cook - - from the URL? maybe i'm stuck with this one.. OR did you mean that i should write it like this: [$cook] ?? Quote Link to comment Share on other sites More sharing options...
flappy_warbucks Posted August 31, 2011 Share Posted August 31, 2011 i should write it like this: [$cook] ?? Exactly that. I.e. // in another file setcookie("Apple","Baking apple pie"); // another file: $cook = "Apple"; if (isset($_COOKIE[$cook])) { echo $_COOKIE[$cook]; } else { echo "Cannot make apple pie"; // program should now break down in hysterical fits of crying and weeping. Get tissues. } it *should* output: Baking Apple Pie Quote Link to comment Share on other sites More sharing options...
antonyfal Posted August 31, 2011 Author Share Posted August 31, 2011 // program should now break down in hysterical fits of crying and weeping. Get tissues. not enough tissues :'( Awesome Spiderwell works perfectly!. If it didn't work i was considering to make a php function to first pull the word from the url, and then include the function in the $_COOKIE function . . Ta!! owe you one . Regards Tony Quote Link to comment Share on other sites More sharing options...
spiderwell Posted August 31, 2011 Share Posted August 31, 2011 its good to know it got resolved Quote Link to comment Share on other sites More sharing options...
antonyfal Posted September 1, 2011 Author Share Posted September 1, 2011 I had to post this further update here: the problem above occured because Mozilla didnt like the [""] and the [''] in the php cookie function and kicked the illegal variable. It seems that IE didnt like my Javascript for placing the cookie, with the output php variable and also kicked the illegal variable error.. if you want to use this code for whatever i now use the following javascript in my html file to place the cookie: // it seems that it did not like the {OUTPUT} direct into the cookie function so i had to first create a "var" and then enter it into the cookie function- - all works perfectly now. <script type="text/javascript"> var word_username = "{THECOOKIE}"; var Values ="1"; document.cookie =word_username+"="+Values; </script> 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.