how to use php to detect javascript and flash plugin?<

liunx

Guest
The subject says it all. I would like to dynamically check for a browser's support of javascript and the flash plugin. I have searched the web for the answers but havent found much. Any info would be appreciated. thanks

Here is an example of what I want to do:


/*
check for javascript here and set $hasJavascript variable
*/

if($hasJavascript == true)
{
//put javascript code
}
else
{
//do something else

}

//do the same as above, but with flashHi musa1982, Two ways,

Macromedia's detection kit

<!-- m --><a class="postlink" href="http://www.macromedia.com/software/flash/Download">http://www.macromedia.com/software/flash/Download</a><!-- m --> /detection_kit/

Or Moock's

<!-- m --><a class="postlink" href="http://www.moock.org/webdesign/flash/detection/moockfpi/">http://www.moock.org/webdesign/flash/de ... /moockfpi/</a><!-- m -->

I haven't tried either of them, but I hear they both work fine. I don't know if there is a way with php.you haven't found much cause there isn't none. you can't detect javascript as it is client side, php is serverside. it only gets what the browser sends.

for flash it is in the flash code. if they don't have flash then the code gives them a link, if you do the code correctly.

ianmh, that is js files and if they don't have js enabled it will not work.I think its the only way to detect it and show a custom message though. For many sites you have to have javascript enabled, like online banking. Anyone know what the statistics are for people disabling it?I have seen 20%+ without Javscript enabled.thanks for the replies. I wont be able to use the javascript method, because javascript might be disabled.

i did find a method do it. here is the code and link:

if(eregi("application/x-shockwave-flash", $_SERVER['HTTP_ACCEPT']))
{
$hasFlashSupport=true;
}

<!-- m --><a class="postlink" href="http://www.sitepoint.com/article/1209/6">http://www.sitepoint.com/article/1209/6</a><!-- m -->

to scout: are you sure that there isnt a way to detect javascript? I ask because the code above lets me detect flash, and flash is client-side also.20%? I guess client-side validation isnt a good idea then.You should never validate data on the client side. Hackers just love to rewrite the page with their own parameters and submit their own form instead.how can that be done? my server processes the input.Originally posted by musa1982
thanks for the replies. I wont be able to use the javascript method, because javascript might be disabled.

i did find a method do it. here is the code and link:

if(eregi("application/x-shockwave-flash", $_SERVER['HTTP_ACCEPT']))
{
$hasFlashSupport=true;
}

<!-- m --><a class="postlink" href="http://www.sitepoint.com/article/1209/6">http://www.sitepoint.com/article/1209/6</a><!-- m -->

to scout: are you sure that there isnt a way to detect javascript? I ask because the code above lets me detect flash, and flash is client-side also.
for one, $_SERVER["HTTP_ACCEPT"] on me gives me */* so that will be invalid detection won't it? and yes I have flash plugin installed.

the browser doesn't give any idea if javascript is enabled. it just doesn't work.

musa1982: if you use php you have all teh control, not the server.scoutt, so do you think everything should be done via php? or some other server side scripting language?that is the point of this thread, you can't tell with serverside language. it is serverside, not client side. the serverside code only gets so much information, and javascript and flash just isn't in it.

flash has it's own detection, clientside, javascript doesn't. it either works or doesn't.

if you find one then I am all ears.

ask in the client side forums and see what they say.Originally posted by scoutt
for one, $_SERVER["HTTP_ACCEPT"] on me gives me */* so that will be invalid detection won't it? and yes I have flash plugin installed.

the browser doesn't give any idea if javascript is enabled. it just doesn't work.

musa1982: if you use php you have all teh control, not the server.

thanks again for the reply. I tested the above flash detection code and it works for internet explorer 6, netscape 7.1, and opera 7.23 browsers. if it didnt work for you, then it may not work for all browser versions.

since php is able to detect the flash plugins and browser types (all client-side data), I thought it could check for javascript...but i guess not.

ill probably just use serverside validation. thanks the help everyone.ok listen, it doesn't just work if there is flash installed for the browser. if you use it to detect if the user has flash installed on a page without flash it will not detect anything. therefore if you detect it on a page tha thas flash it will detect it but what good does it do you, it is pointless as they are already on a flash page. then you might has welll just give them the <object> tag and detect flash that way and give them a link.


'HTTP_ACCEPT'
Contents of the Accept: header from the current request, if there is one.
that bold part is important, like for me and a page that has no flash running it will be none. hence there is no way to detect it with php.possible javascript detection:

<script type="text/javascript">
location="page.php?js=yes";
</script>
<noscript>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=page.php?js=no">
</noscript>

but i did not test that!!
 
Top