nezbo Posted November 12, 2007 Share Posted November 12, 2007 Hi all I have a bit of a dificault one. i am using php and mysql to verify the login's, and i am using a .js file for nav menu's, but i want to use a php to let people see what menus that they are allowed to see. hope this make sence... e.g. i have a "edit user" page in a nav menu dropdown and i dont want any body to see it apart from the administrators. Neil Link to comment https://forums.phpfreaks.com/topic/76972-php-in-a-js/ Share on other sites More sharing options...
Dragen Posted November 12, 2007 Share Posted November 12, 2007 You could try AJAX, but I'm not sure if it'd work, as I'm not very good at it, or you could simply add a couple of lines to your .htaccess file: RemoveHandler .js AddType application/x-httpd-php .php .js That will allow all .js files on your server to run php as well. Although, unlike .php files, I think if someone views the source code of the .js file they would see the php code.. not sure though. Link to comment https://forums.phpfreaks.com/topic/76972-php-in-a-js/#findComment-389756 Share on other sites More sharing options...
Vikas Jayna Posted November 12, 2007 Share Posted November 12, 2007 A javascript file can be served through php also. The php file can simply process and decide what should be the javascript code and simple throw that code to the browser. The following line will have to be added to the top of the php file in order to tell the browser that the content is javascript: header("Content-type: application/x-javascript"); Also, the file extension can be kept .js and mod_rewrite can be used in apache to direct the file to a php file like this: RewriteRule ^abc.js$ abc.php [T=application/x-httpd-php] The above line cab be used in .htaccess. This way the browser will call file "abc.js" but actually "abc.php" will be executed on the server. Link to comment https://forums.phpfreaks.com/topic/76972-php-in-a-js/#findComment-389758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.