Jump to content

print code on page view


PlagueInfected

Recommended Posts

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

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

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

<?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;
}

Archived

This topic is now archived and is closed to further replies.

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