Jump to content

PHP in a .js


nezbo

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.