Page 1 of 1

Building a Javascript query in php with MD5()

Posted: Thu Jun 25, 2009 1:05 pm
by laurus
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi I am building a javascript function in php. It is going swimmingly until I get to the part where I try to use the JS variable 'file' in the MD5() function..
the 'file' var works fine in the section of the code without the MD5().

Code: Select all

 
<?php 
    echo  "<SCRIPT LANGUAGE=\"Javascript\">\n";
    echo  " <!--\n";
    echo  "     function bg(file)\n";
    echo  "     {\n";  
    echo  'window.location = "http://bitcast-g.bitgravity.com/suze/members/files/area3/members/VIDEOS/" + file + "?e='.$t.'&h='.MD5("xxxxxxxxx/suze/members/files/area3/members/VIDEOS/' + file + '?e=".$t).'   "';
    echo  "     }\n";
    echo  "     //-->\n";
    echo  " </SCRIPT>\n";
?>  
 

Code: Select all

<A href="javascript&#058;void()" onClick="bg('2000_3475_1000.wmv');return true">Link</A>

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Building a Javascript query in php with MD5()

Posted: Thu Jun 25, 2009 2:17 pm
by pickle
This Javascript won't be run until PHP has completed & sent the output to the browser. Consequently, the Javascript 'file' variable won't be set until the function is called in the browser - way after PHP (and the md5() function) have finished running.