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

Link to comment
Share on other sites

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

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