Jump to content

php variable error, with this cookie code.


antonyfal

Recommended Posts

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.

Link to comment
Share on other sites

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] ??

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

// 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 ;D.

Regards

 

Tony

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.