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'; } ?> Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/ 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. Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915387 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915389 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915390 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915393 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? Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915397 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) Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915399 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. Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915404 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915405 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? Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915406 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 '; } ?> Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915412 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. Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915415 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915416 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. Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915419 Share on other sites More sharing options...
PlagueInfected Posted September 9, 2009 Author Share Posted September 9, 2009 yup pretty much Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915420 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. Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915422 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. Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915424 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915430 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) ?> Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915433 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; } Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915437 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915439 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..... Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915445 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 Link to comment https://forums.phpfreaks.com/topic/173660-print-code-on-page-view/#findComment-915447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.