Friday, December 16, 2011

Removing Blogger/Blogspot Branding from your Blog

When you create a blog with blogspot.com, there should be this annoying navigation bar at the top. Annoying because it's your blog and you should be able to decide whether you want to keep it there or not. Sure, it's got options to "follow" and "share" the blog, blah blah. But I would have liked it if I were given a choice to keep it or not. Then there's the "Powered by Blogger" footer. Not something I want there at the bottom. Or anywhere else.

Blogger gives you an option to insert custom CSS rules. You should find this option under
Template Designer > Advanced > Add CSS. Once there, you should be able to set new styles and even override existing ones.

Removing the Navigation Bar and Footer
Add the following lines in the Add CSS space in the Template Designer.
.navbar {display:none}
#footer-3 {display:none}
#HTML1 {margin:0px}
Here, line 1 is to hide the navigation bar while lines 2 and 3 are for hiding the footer. To add your own custom footer, go to Layout and insert a new HTML/Javascript gadget with something like
<div style="text-align: center;">
© 2011 Your name.
</div>
 at the bottom near the original footer. Click on save arrangement. Your changes should now be visible on your blog.

What else...
If you notice the search box at the top in this blog, it does not have the customary "Powered by Google" branding. Also I have tweaked the search results box a little to make it go better with the theme. I use the following code for this. You are welcome to use it for your own blogs as well. I have to admit, it's just a little buggy. But it's ok. This is a Blogspot blog after all. If you were actually serious, you would be using Wordpress.
.gsc-branding {display:none}
#uds-searchClearResults {border-style:none}
.gsc-tabHeader .gsc-tabhActive {border-left: none;border-right: none;border-top: none;}
#uds-searchControl .gsc-tabHeader.gsc-tabhActive {border-style: none;border-width: 0;}
.gsc-resultsbox-visible {box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);border-style:none}
#uds-searchControl .gsc-results {border-style: none;border-width: 0px;width: none;margin: 20px -16px;}

Tuesday, December 6, 2011

PHP Compiler Part Two: An Introduction to Apache and PHP

I use XAMPP. Relieves me from the hassle of having to download and install Apache and then install PHP and then configure them to work with each other. Things get only more complicated if I want to install MySQL, Perl, etc. "XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl". Yes, it is. And not just that, it comes with phpMyAdmin, PEAR (the PHP Extension and Application Repository), Perl, Mercury Mail Transport System, etc and even a bunch of modules for Apache, all of them configured and ready to use. The latest version even comes with Tomcat to run Java Servlet Pages.

Apache is the actual web-server. It receives requests from browsers. PHP works under Apache. Apache's functionality can be extended by Modules. They may be loaded through directives specified in the Apache configuration file located at Apache/conf/httpd.conf. Apache also supports CGI. Here, Apache calls an executable to generate the web page that is to be given as response back to the browser. The CGI script can receive POST variables via stdin or Apache can also set environment variables which can be accessed within the CGI script. The output is given back to Apache via stdout.

PHP can be run either as an Apache module (mod_php) or as a CGI program. From what I understand, running PHP as a module is faster while running it as a CGI executable is more secure. XAMPP keeps its configuration separate from the main Apache config by using an Include directive (similar in function to C's #include) in httpd.conf to include httpd-xampp.conf.

Running PHP as an Apache module
When running PHP as a module, you should see something like php5apache2.dll or libphp5.so in your Apache/modules folder. .so files are shared libraries. They are the Unix/Linux equivalent of .dll files in Windows. You might be seeing a combination of .dll and .so files in your modules folder. The extension really doesn't matter.
LoadModule php5_module modules/php5apache2_2.dll

<IfModule php5_module>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
A configuration like the one above specifies the module to load and if the php5_module has been loaded, Apache is instructed to recognize all requests that match the regular expression \.php$ as PHP scripts.

Running PHP as a CGI program
When running PHP in this mode, you should notice a php-cgi.exe in your php folder. It is the CGI version of the PHP interpreter. If you have installed xampp in your program files folder, your config should look something like this.
ScriptAlias /php-cgi/ "C:/Program Files/xampp/php/"

<IfModule !php5_module>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php-cgi
</FilesMatch>
<IfModule actions_module>
Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
</IfModule>
</IfModule>
To replace something like PHP, I realized I would have to build my own module for Apache which I could then set as the handler for PHP scripts. More on that in Part 3.

Saturday, December 3, 2011

PHP Compiler Part One: Translating PHP

A PHP Compiler. Hmmm.. That seems new doesn't it? Apparently not. It seemed like a radically-different-world-changing idea when it first struck me one morning. But later that day I learnt tht I was beaten to it by Facebook.... and a whole lot of other people! Anyway, this seemed like an interesting project.

PHP is a scripting language. Scripts are compiled into Opcodes and run on a virtual machine called the Zend Engine. It's a bit like the JVM for Java, except here, scripts have to be compiled each time before execution. In Java, code is compiled once into .class files which are then run on the JVM. The basic idea behind this project is to make PHP faster by compiling it. Machine code is supposed to execute faster than any interpreted language right?

Obviously I was going to need some help with this. Google's always been a good friend of mine at times like this. What I was looking for was something to translate PHP code to C/C++ so that I could use gcc/g++ to compile it to machine code. These are some of the projects I came across.

php2cpp - "The PHP to C++ Translation tool". Downloaded the source, compiled it and translated a tiny script. php2cpp uses a set of translation rules (these) to perform statement-by-statement translation of PHP code to semantically equivalent C++ code. That's all well and good. But then what about PHP's inbuilt functions?? Surely C++ does not have equivalent functions for Every Single function in PHP. Or what about code that makes use of extensions??? I didn't bother finding out as I wasn't able to get anything to actually compile after translation with php2cpp.

Then there's Roadsend. According to the description on Roadsend.com, you can use it to make web applications with FastCGI or even use it with PHP-GTK to make offline applications (with an embedded web-server). Hmmm, desktop application development with PHP. Weird, but if you are interested, check out Roadsend and WinBinder.

Facebooks HipHop - You should probably read this. Definitely better than anything I can write about it here.

PHC - This is what I found next. PHC has been in development since 2005. It supports the entire standard library of functions in PHP. The author claims in his blog that he was sort of a pioneer in this field (and I believe him. He's got a PhD in "compiler optimizations, static analysis and scripting languages") but back then he wasn't able to convince anyone to "give a shit", not even Facebook. And that was before they came up with HipHop. But now that Facebook's on-board, everyone's interested again in the field! Beware, the idiots on the Internet will have you believe that Facebook invented the concept. Now you know the truth.

BinaryPHP is what I eventually ended up using (mainly because it worked on the first try). I did not test it extensively but from my experience, I can tell you that it supports a few, not all, of PHP's standard library functions. It even supports the MySQL functions. I'll admit, I ended up not testing anything else once I got this working. May be some other time. This one works after all.

So ok. I can translate PHP code to C++ code and even compile it. Now I needed it to work under Apache, my web-server. More on that in Part 2.