Setcookie before everything else

HI,

 

I Have a javascript that sets a cookie.

 

What file would be the best way to do it

 

Thanks

Quote · 11 Apr 2011

Let me explain in more details :

 

1- I have a javascript (I tried to find a php script that detect if flash is installed, but I found nothing that works, so I use java):

var MM_contentVersion = 6;

var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

if ( plugin ) {

var words = navigator.plugins["Shockwave Flash"].description.split(" ");

for (var i = 0; i < words.length; ++i)

{

if (isNaN(parseInt(words[i])))

continue;

var MM_PluginVersion = words[i];

}

var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;

}

else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0

&& (navigator.appVersion.indexOf("Win") != -1)) {

document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag

document.write('on error resume next \n');

document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');

document.write('</SCR' + 'IPT\> \n');

}

if ( MM_FlashCanPlay ) {

document.cookie = "flashDetection" +"="+ "yes";

} else{

document.cookie = "flashDetection" +"="+ "no";

}

 

2- In a php file :

if ($_COOKIE['flashDetection'] == "yes"){

some php actions

}

 

3- The problem is that the cookie is written after the site loads, I have to refresh so that the php works.

 

Is someone knows how to fix this ?

 

Quote · 12 Apr 2011

That is actually normal. When a cookie is set, the page has to be reloaded to actually read that cookie, thus they cannot be placed on the same page.

I am guessing you're trying to get this to work on the index page of the site.

I have something you can try.

On most servers, index.htm or index.html is loaded if it exists before a index.php.

So, you could try putting your script in a index.htm file. Add a javascript redirect to index.php after the cookie is set.


https://www.deanbassett.com
Quote · 12 Apr 2011

Thanks a lot

 

it works perfectly.

Quote · 13 Apr 2011
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.