PlagueInfected Posted September 9, 2009 Share Posted September 9, 2009 im trying to code something to where if you view a page, the script either dies or prints something until you leave the page. I planned to do this with my css page in php code i tried this code here, however even when i left the page it still didn't do anything. <?php $csspage = '/css/v5.php'; $currentpage = '$_SERVER['REQUEST_URI']; if ($csspage == $currentpage) { die('this page is encrypted!'); } else { header('content-type: text/css'); echo 'CSS CODE'; } ?> Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 Do you have error reporting turned on? You are missing one single quote in the end of the echo. Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 ya i do, and the apostrophe is there when i edit the post Quote Link to comment Share on other sites More sharing options...
richrock Posted September 9, 2009 Share Posted September 9, 2009 not sure if this'll fix it but... echo 'CSS CODE; should be: echo 'CSS CODE'; (extra ' missing)... and $currentpage = '$_SERVER['REQUEST_URI']; has an extra ' - should be $currentpage = $_SERVER['REQUEST_URI']; You may want to echo out the REQUEST_URI to see if it's reading the same file or not... R Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 done that and it's reading it, however still disables even away from the page and not viewing it Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 What richrock mention is the same as I did. But now I am not following you.. please elaborate your problem? Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 basically put... when i put my code in my page, the script will work but when im not viewing or on the page, the script still executes. pretty much, im trying to get the script to ONLY work if you're on the page (viewing it) Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 How do you know the script still executes if you are not on that page anymore? The script execution ends when the page is loaded. If you after that leave the page the script can not be executing anymore. Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 because im using it on a css based php page. i know it works no more because my css is gone when im visiting the main pages Quote Link to comment Share on other sites More sharing options...
richrock Posted September 9, 2009 Share Posted September 9, 2009 is it part of a require() or an include() for the page? EG : require('/css/v5.php'); what calls the css in the first place? Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 the coding is like this <?php $page = '/css/v5.php'; $currentpage = $_SERVER['REQUEST_URI']; if ($page == $currentpage) { print('this page is encrypted'); } else { //calls the css header('content-type: text/css'); echo ' PHP CODE '; } ?> Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 What is css based php page? PHP has nothing to do with CSS and vice versa. I don't get this. Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 im coding it to where you view the css page you get a message instead of the code. i did it but unfortunately it still executes when not viewing the page, i know that because when i use the scripting on it, the whole site loses it's CSS Quote Link to comment Share on other sites More sharing options...
richrock Posted September 9, 2009 Share Posted September 9, 2009 Are you trying to prevent access to the CSS? That's the impression I got when you wrote: im coding it to where you view the css page you get a message instead of the code. Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 yup pretty much Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 You can't prevent people seeing the CSS you want to use on your pages. If the CSS is used in the page, it is also then viewable in a way or another. Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 god dang, and i saw it used by someone too but he took it off. Quote Link to comment Share on other sites More sharing options...
richrock Posted September 9, 2009 Share Posted September 9, 2009 You can put css into a php file and prevent direct access, but determined people with tools like WebDev toolbar or Firebug will still be able to read outputted CSS. <?php header("Content-type: text/css; charset: UTF-8"); ?> <!-- insert CSS stuff here --> <!-- save as css_filename_css.php and include in the source PHP files using include(). --> This means there is no attached CSS file, but it's really more hassle than it's worth. There's nothing worth preventing seeing in a CSS file anyhoo. Use this linky to prevent direct access to files - http://www.namepros.com/programming/408685-php-prevent-direct-url-typing.html Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 how do you think i should code this? and do i echo the css or just code it in with no echo? would it be like this... <?php my if on page statement ?> <?php header('content-type: text/css; charset: utf-8'); CSS CODE BELOW (no echo) ?> Quote Link to comment Share on other sites More sharing options...
richrock Posted September 9, 2009 Share Posted September 9, 2009 <?php // Original page file eg index.php define('IS_IN_SCRIPT',1);// define a flag for the CSS bit include('/sourcetocss.phpfile'); // Rest of the page ?> Then... create the site_css.php file - <?php // CSS file in PHP format if (!defined('IS_IN_SCRIPT')) { // if our flag is not defined, user is accessing our file directly die('I am sorry, you can not access this file directly.'); exit; } // else, continue the page header("Content-type: text/css; charset: UTF-8"); ?> /* CSS code below */ body { font-family:Arial, sans-serif; font-size:11px; } Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 sweet it works but unfortunately it doesn't work on my site check it out, the css is gone like before... http://plagueinfected.com Quote Link to comment Share on other sites More sharing options...
richrock Posted September 9, 2009 Share Posted September 9, 2009 Bit stumped myself, it should render the CSS due to the header function..... Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 it did it but it isn't functioning Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.