Welcome Guest, Not a member yet? Register   Sign In
JS and CSS as a php file
#17

[eluser]slowgary[/eluser]
Ahh... back to the original post.

Mareshal, you can echo your JS or CSS from PHP as stated above. You should add appropriate headers as umefarooq mentioned. The easiest way to "protect" the files like the site you found is to do a check in your "css.php" or "js.php" for a defined constant, and only echo the contents if the constant is defined. So:

Code:
<?php
//js/script.php
if(defined(APPNAME))
{
     $username = "Bob Dole";
     header('Content-type: 'text/javascript');
     //this javascript uses the jQuery framework
     echo <<< JAVASCRIPT
     $(document).ready(function(){
          alert('Welcome, $username');
     }
JAVASCRIPT;
}
?&gt;
Then in your view:
Code:
&lt;?php define('APPNAME', 'skynet.v1'); ?&gt;

&lt; script type='text/javascript' src='/js/script.php' &gt;&lt; /script >

Keep in mind that this isn't any real protection as users still get those files when they view your page in full. It might stop a noob from viewing your JS or CSS directly, although plain old compression would probably be slightly better as well as have the added benefit of shrinking the download.


Messages In This Thread
JS and CSS as a php file - by El Forum - 07-08-2009, 01:18 AM
JS and CSS as a php file - by El Forum - 07-08-2009, 01:57 AM
JS and CSS as a php file - by El Forum - 07-08-2009, 02:21 AM
JS and CSS as a php file - by El Forum - 07-08-2009, 05:51 AM
JS and CSS as a php file - by El Forum - 07-08-2009, 06:04 AM
JS and CSS as a php file - by El Forum - 07-08-2009, 03:58 PM
JS and CSS as a php file - by El Forum - 07-09-2009, 08:53 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 09:07 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 09:31 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 09:59 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 10:04 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 10:11 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 11:25 AM
JS and CSS as a php file - by El Forum - 07-09-2009, 09:32 PM
JS and CSS as a php file - by El Forum - 07-09-2009, 09:58 PM
JS and CSS as a php file - by El Forum - 07-09-2009, 10:43 PM
JS and CSS as a php file - by El Forum - 07-09-2009, 10:55 PM
JS and CSS as a php file - by El Forum - 07-10-2009, 12:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB