Archive for the ‘PHP’ Category

h4×0r (Hacker) / The Matrix Theme for WordPress

My h4x0r Theme

I thought I’d try something different ;)

I’ve been playing with wordpress for nearly a year now, and thought it’d be cool to make a publicly available theme, I wasn’t sure on what to do so I thought I’d start with a simple pallet. My theme is a black on green code looking theme, you know the hacker site style; to make it more interesting I added some matrix references, and silly bits of php code.

The theme has been tested on wp 1.5 & 2.01 (including a blank one as requested on the codex) , there is a screenshot and I’ve also installed a theme switcher so you can demo it :D

Multiple Loops in Wordpress

I wanted to run the wordpress loop on my php page more than once, & I don’t know if I’m the only person, but I found the offical multiple look example hard to swallow.

Google found is nima’s how to which was useful, but I wanted to take it further; the problem was I wanted a function.

This is what I came up with:

<?php
require(’path_to_wordpress/wp-blog-header.php’);
?>

<?php
function show_posts_from_cat($MYCAT){

?>

<ul>
<?php if (have_posts()) : ?>

<?php $my_query = new WP_Query(”category_name=$MYCAT”); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>

Google Adsense code (javascript) in wordpress pages / posts

For ages I could not work out why google ad’s included within a wordpress page didn’t work (in fact this applies to a post too). When google support pointed out that there was <br/> ’s in my code the penny finally dropped.

So here’s the deal, I pasted the following code into my page: (In the wordpress dashboard)

firefox ad
<!– FireFox Referral –>
<script type=”text/javascript”>
<!–
google_ad_client = “pub-6732086233580907″;
google_ad_width = 180;google_ad_height = 60;
google_ad_format = “180×60_as_rimg”;
google_cpa_choice = “CAAQyaj8zwEaCIwcWMzeycafKMu293M”;
//–>
</script>
<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>

adsense ad
<!– Adsense Referral–>
<script type=”text/javascript”>
<!–
google_ad_client = “pub-6732086233580907″;
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = “180×60_as_rimg”;
google_cpa_choice = “CAAQ__qy0gEaCP_s0gMhUOtXKL3D93M”;
//–>
</script>
<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>

Implementing Adsides in wordpress

I’ve decided to take a tip from the pro’s and separate my useful content from waffle. The blogging term appears to be asides , and photomatt has simple post on how to do it. Basically the idea is, that asides content doesn’t take up as much space on your blog, so readers can easily see reference or important material, and if they’ve got some spare time read your thoughts.

Implementation is quite straight forward, assign a category for these less important posts - for me that’s blog - and then on you theme index.php add the something like the following code:

Nagios Ping And Traceroute Tool Version 0.3

This has been on my to-do list for a long while….I have finally release a bundled package which includes bug fixes from users, a big thank you goes out to you all.

Here’s a copy of my changelog:

Version 0.3
Package bundle of 0.1 & 0.2 - Plus valid html code for exit errors.
http://www.linickx.com/blog/archives/92/nagios-ping-and-traceroute-tool-version-03/
Date: 16.12.2005

Version 0.2
Commented out hosts problem.
http://www.linickx.com/blog/archives/81/nagios-ping-tool-another-hack/
Date: 09.11.2005

Version 0.1
NagiosQL - Multiple hosts.cfg files support.
http://www.linickx.com/blog/archives/79/nagios-ping-tool-nagios-ql/
Date: 08.11.2005

Version 0
Initial Release.
Nagios Exchange Release Date: 28.09.2005

Writing a PHP Page for the googlebot / google’s cache

Here’s something cool to share.

My calcylator project is written in php, it’s one of those “on-line tools” where users can create an account, log in, and can calculate personal profit & loss sheets for ebay.

Like most websites there are “log in” sections, now these pages need to be dealt with differently for search engines & users. Search engines will not be able to log in, but you may still want to deliver some content to them. Take my example, calcylator is running google adsense, and for adsense to work the googlebot (search engine) needs to be able to “see” some content, thinking this through, every time googlebot visited the log in or other protected pages all it would see is “access denied” error pages.

Nagios Ping Tool - Another Hack

I’ve received a patch from ed.davison, if you have commented out hosts in your config, you’ll get odd \”address - hostname\” results in the drop down list. Ed’s patch fixes that; thankx :-D

At the moment you’d have to apply the patch your self from the below; but I have a official revision in the pipeline.

Nagios Ping Tool & Nagios QL

Recently I had a request from rex to modify my nagios ping tool (Official Nagios Exchange page); he wanted to use the tool with his nagios configuration.

Rex appeared to be using Nagios QL (Which I believe to be a nagios management tool) , now QL handles nagios config slightly differently . The Ping Tool reads the nagios hosts.cfg file, and turns it into a couple of arrays to use for ping & display, with QL they generate multiple hosts.cfg files, one for each hosts.

Perhaps a short way of saying it, Rex needed to read in multiple hosts.cfg files from a directory, and below is the hack to do it :)

PHP - Nagios Ping & Traceroute Tool

Another day, another mini project.

My place of work pretty much demanded the need for our monitoring guys (i.e. people that stare at the nagios screen, waiting for red things) to have the ability to run traceroutes from nagios to the effected node - The twist in the story was that they wanted to do it from a browser !

So, I thought, that’d be an easy php script then :cool: , well to be honest it took a little longer than expected, mainly because I don’t really understand regular expressions (yet).

Nagios-ping-tool Is a package of small scripts :

PHP - Nagios Simple CFG Gen.

Nagios
.. or nagios ;) is great, I use it a lot.

In my continuing quest to cure command line phobia I’ve written a small (& Basic) php script that can generate some sample configs. Simply type in the IP of what you want to monitor , tick a couple of boxes, and copy & paste what you get into the end of your config files - nice :cool:

There’s a Demo Site here : http://www.linickx.com/index.php?content=nagios
and the Source here: http://www.linickx.com/files/php/nagios-simple-gen_php.txt

UPDATE:
Also available at nagiosexchange.org: http://www.nagiosexchange.org/Configuration.20.0.html?&tx_netnagext_pi1[p_view]=327

PHP Snippet: Reverse Proxy ?

I’m not suffering from Blog Burnout, just a little playstation distraction ;) Actually, I’ve spent a lot of time learning PHP for my potential new project; during this I found the function: file_get_contents, which in turn leads me to ask:

Is it possible to make a PHP Reverse proxy ?

I’m thinking yes, but it wouldn’t be easy. file_get_contents allows you to open a file or even a URL from a PHP script running on your webserver, just this simple thought gave birth to this snippet of code:


<?php
$URL=$_GET
["url"];
$self=$_SERVER["PHP_SELF"];

if ( $URL == "") {
?>
No URL Given:

This is cool - Kplaylist

I’ve found this cool MP3 steaming software, easier to setup than icecast/ices & more appropiate for home users. :D Kplaylist uses mysql & php to give you a multi user website for your music directory, you can build playlists & stream music, and the album art is a nice touch. It even supports mp3 streaming over ssl, if only I can get the SSL patch for xmmsto work !

Check it out @www.kplaylist.net/ :cool:

PHP - want a random quote ?

I thought my site was missing something, perhaps a little bit of dynamic text , so now we have it ! Below my logo random one liner quotes will appear :cool:

I found the basics at totallyphp but it only read the quotes from an array, not a file, so: I added the file function & turned the script into a function :D

If you too want simple random quotes to include the source is here. The usage is simple, create a file called quotes.txt with quotes, a new one on each line (make it world readable) ; by default if you then call quotes.php it’ll choose a line & print the text… if you comment out echo randomquote(); you could include quote.php in other code :idea:

PHP-Cat - Free download ;-)

It’s the usual story, bored in a travel lodge finishing some blog drafts / projects I’ve got saved.

PHP-Cat is an example of how one can use the browser php script that I published; PHP-Cat is a web based tool that allows you to browse the file system of the webserever / host , you can then select a text file and view it through your broswer. What’s clever is that you are not just limited to files in a webservers root directory, you can view any* directory ! (Needless to say, this script cannot by-pass filesystem security, see comment below.)

PHP-ICES BETA Released !

This is my 1st mini-project ! :D

Written completely in PHP it’s a web front end to manage ices.

A short while ago I stubled across www.icecast.org whilst looking for a way to stream MP3’s from my house to my desk @ work ;) To Stream MP3’s you need a Streaming Server , i.e. something to stream audio to the clients and a Broadcast Server i.e. something to broadcast your audio file (*.mp3) to the streaming server. I’ve used both icecast (Streaming Server) & ices (Broadcast Server) , both of which only have shell (command line) & text file config tools, not exactly pretty & lots of typing :(