FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home  »  PHP  »  Use php.ini to replace html with anything

by comment


What to include?

By including a php file using php.ini, you can replace the headers in your html with dynamic headers.

Include a php file that contains a function to replace html with different html. You include a file from your php.ini like auto_prepend_file /web/askapache.com/config.php?


config.php example from: Effective way to update your blog's header scripts

<?php
function Config($page)  {
 
$googleAnalytics = '<!-- Google Analytics -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">_uacct = "UA-188760-13";urchinTracker();</script>
';
 
$quantcast = '<!-- Quantcast  -->
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
<script type="text/javascript">_qacct="p-0dzSWakPjpGqM";quantserve();</script>
<noscript><img src="http://pixel.quantserve.com/pixel/p-0dzSWakPjpGqM.gif" style="display: none" height="1" width="1" alt="Quantcast"/></noscript>
';
 
$mybloglog = '<!-- MyBlogLog -->
<script type="text/javascript" src="http://track.mybloglog.com/js/jsserv.php?mblID=2007020306380804"></script>
';
 
$pages  = array(); // Add pages (relative to the public site root) that should be ignored
$ip    = array(); // Add IP addresses that should be ignored, for instance you don't want to track yourself or your company's visit to your blog.
 
if (
  strpos($page,'frameset') !== false ||
  (!empty($ip) && in_array($_SERVER['REMOTE_ADDR'], $ip)) ||
  (!empty($pages) && in_array((isset($_SERVER['PHP_SELF']) && !empty($_SERVER['PHP_SELF']))?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME'], $pages))
  )
{ return $page; }
$replace = array
  (
    '</head>',
    '</head>'
  );
  return str_replace($replace, "n{$googleAnalytics}nn{$quantcast}nn{$mybloglog}r</head>", $page);
}
ob_start("Config");
?>

php.ini

auto_prepend_file

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the include() function, so include_path is used.The special value none disables auto-prepending.

auto_append_file

Specifies the name of a file that is automatically parsed after the main file. The file is included as if it was called with the include() function, so include_path is used.The special value none disables auto-appending.

Note: If the script is terminated with exit(), auto-append will not occur.

Tags

March 9th, 2007

Comments Welcome

Popular Articles
My Online Tools

Related Articles
Newest Posts
Twitter


  • @askapache · Jul 21
    Magic spells for sending thoughts across time? Books
  • @askapache · Jul 20
    TV is just a relic of the previous generation. We just don't know it yet.
  • @askapache · Jul 20
    I will never go back on my ideals, no matter the cost. I'll never let the economic vultures steal my dreams. I'd rather give up the ghost
  • @askapache · Jul 18
    I don't want a better seat, I want control of the engine
  • @askapache · Jul 14
    No matter how good u r, there will always be someone 2x, 5x, 100x better. This is true for me and everyone. No direction but forward.
  • @askapache · Jul 12
    Heads up, I'll DDoS the f out of askapache next week, to see how resilient it really is :) - will try to overflow disk, net, and ip stack
  • RUN GCC! This is a typical shirt I wear, from the  t.co/46LYbFr4k2  shop. A clerk at the LQ recognized it!  t.co/jjmT0dkCPu 
  • Merlin the Magician  t.co/iMmRbanUi4 
  • ROGUE CODE - Latest novel from @markrussinovich  t.co/apkn0LoPIt 
  • RTFM - surprisingly very helpful and way more comprehensive than it looks! @redteamfieldman #pwnAllTheThings  t.co/xiaJ5g0aC9 
  • Dear Hacker - Letters to the Editor of 2600, from Emmanuel Goldstein  t.co/JCfLab7FAJ 
  • The Mythical Man-Month - Essays on Software Engineering, by Frederick P. Brooks, Jr.  t.co/ilWN5GHElr 
  • "where wizards stay up late" - The Origins of the Internet. Favorite book detailing the birth of the net and IMPs  t.co/gY9VTGJgZz 
  • ZERO DAY - read before Trojan horse  t.co/pPMLGDJv8P 
  • Trojan Horse, a novel!  t.co/Hf8EtYaZVa 
  • The Hacker Playbook - very nice high level overview of attacks  t.co/lHwNVWi61u 
  • Clean Code - A Handbook of Agile Software Craftsmanship  t.co/hnJX0x1qIc 
  • Secrets of the JavaScript Ninja - By my absolute favorite JS hacker John Resig!  t.co/tZ42ljmcCl 
  • Hacking Exposed 7: Network Security Secrets & SolutionsMy all time favorite, basic but thorough and accurate.  t.co/jycW0RDVtZ 
  • Empty words will be no surrogate for cold resolve. Pain is nothing.  t.co/qXjpRxbjCw 

Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman






[hide]

It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

| Google+ | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain