Want to have a style switcher that lets your site’s visitors choose a different style sheet? Want it to work even if there is no JavaScript support? The trick is to use a server-side language like PHP, which is what I use for my style switcher.
Using PHP to let the user switch to a different CSS file is nothing new. But it is one of the things that I am often asked about, so I thought it would be good to have a write-up to refer people to in the future.

As I mentioned this will work when JavaScript is disabled. It will not work when cookies are disabled, however. Nothing bad will happen, but it simply won’t work and the user will be returned to the same page they were on. Just to make you aware of that right from the start.

I use this style switcher to let visitors switch between two different layouts (“Zoom” and “Normal”) here on 456 Berea Street. If you want to let the user choose between more than two stylesheets you will need to come up with a different solution.

I wouldn’t call myself a PHP expert by any means, so if you think my code could be improved in any way, please let me know.

To switch styles, all you need to do is activate the link to the styleswitcher. As you may have noticed if you have tried that, the URL that invokes the styleswitcher is always the same: /styleswitch/. The link leads to a php file that looks like this:

  1. <?php
  2. $layout = (isset($_COOKIE['layout']) && ($_COOKIE['layout'] == "zoom")) ? "main" : "zoom";
  3. setcookie("layout", $layout, time()+31536000, '/');
  4. $ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "http://{$_SERVER['SERVER_NAME']}/";
  5. header("Location: $ref");
  6. ?>
Here’s what happens, line by line:

  • Line 2: If the layout cookie exists (the browser has been here before) and has the value “zoom” (the user has switched to Zoom layout), $layout is set to “main”. Otherwise $layout is set to “zoom” (the browser doesn’t accept cookies, the style switcher has not been used with this browser, or the user has switched to Normal layout). Note that “main” and “zoom” are the file names (except for the .css extension) used for the respective styles. Change these values to match your file names.
  • Line 3: The value of $layout is stored in a cookie.
  • Line 4: If a referer header exists, its value is stored in $ref. If it doesn’t exist, $ref is set to “http://{$_SERVER[‘SERVER_NAME’]}/” as a backup to redirect the browser to the home page.
  • Line 5: The browser is redirected to the URL stored in $ref.
On all pages a check is performed to decide which stylesheet to load:

  1. <?php
  2. $layout = (isset($_COOKIE['layout']) && ($_COOKIE['layout'] == "zoom")) ? "zoom" : "main";
  3. ?>
If a cookie exists and its value is “zoom”, $layout is set to “zoom”. Otherwise, $layout is set to “main”. At this point $layout contains the name of the CSS file that should be loaded.

Finally, when loading the main style sheet the value stored in $layout is inserted instead of the file name in the @import path:

  1. <style type="text/css" media="screen,projection">
  2. @import '/css/<?php echo $layout; ?>.css';
  3. </style>
And that’s it. Use it, spread it, improve it.
Thursday, March 11, 2010

Automated News Aggregator: PHP RSS Reader

PHP RSS Reader is an application which can crawl an unlimited number of feeds & presents them with an easy-to-use interface.
For an organized navigation, It is possible to create categories & place feeds inside them.
A handy feature is "keyword-based" categories which can auto-move items with the keywords mentioned into the related categories which is great for anyone who follows multiple feeds but hunts for specific keywords.


PHP RSS Reader comes with a complete admin panel where every setting can be controlled.
The application creates SEO-friendly URLs for every category & article which is important for anyone who will use PHP RSS Reader for creating a feed-based website rather than using it as a personal feed-reader.
It is possible to change the look & feel of the interface by simply playing with the CSS files.
There is a web-based installer that help making the application online in a few minutes.
PHP RSS Reader comes with 2 versions:
The application is a must-check for anyone looking for an advanced RSS reader, planning to create a feed-based website or integrate feeds into an application (where PHP RSS Reader can be used only as the backend engine).
P.S. This post is a sponsored review.

chive is an open source & web-based MySQL management application that is built with PHP.
It can achieve the most common tasks like creating, editing & executing:
  • databases
  • tables
  • indices, keys, triggers, views, routines
  • privileges management
  • import/export


The application has a built-in editor with syntax-highlighting which is nice when running complex queries & an easy-to-use interface that makes browsing fast.
chive has one major fallback (which may pr may not effect you): it only supports MySQL 5+.

Wednesday, March 10, 2010

Ajaxed PHP Calendar For Displaying Availability

Ajax Availability Calendar is an open source PHP application for displaying the availability of an item (hotel room, appointment, etc.).
It comes with an Ajaxed administration panel (multiple admin users are supported) to manage the calendar.



The application is multilingual & unlimited number of items can be added under multiple languages.
Months displayed are changed with Ajax requests where no refreshes are required & it can be totally styled via CSS.
Phpns is an open source news/content management system that will enable you to add dynamic content to any website with one line of code.

The application is not a complicated or a full-featured CMS. Rather, it is a simpler one which is very suitable for managing basic websites.

Phpns

It comes with variables like adding pagination, displaying summary or the full content, RSS generation & much more.

Phpns is multi-user, can create SEO-friendly URLs & optionally, helps you create/manage templates.

The application is built with PHP, uses MySQL for storing the data & comes with a web-based installer.

Requirements: PHP & MySQL
Website: http://phpns.alecwh.com/
Thursday, September 17, 2009

Ajaxed MySQL Table Editor

Mysql Ajax Table Editor is an open source web application for easily editing MySQL tables & creating admin pages almost instantly.
Besides the standard "add, edit, copy, delete, view" functionality, records can be paged, searched & exported to CSV.


It is possible to JOIN multiple tables to generate a custom view (+ apply any other functions on this view) with the help of a configuration file. Also, column names displayed can be customized for a better presentation.
MySQL Ajax Table Editor has permissions support which can be set on a per column or table basis for limiting functions.
Users can hide/show & re-order columns which is very useful when working with the data.
The application works with both PHP4 & PHP5 and comes with 5 ready-to-use languages where new ones can be created.

Requirements: PHP4 or PHP5
Compatibility: All Major Browsers
Website: http://www.mysqlajaxtableeditor.com/
Demo: http://www.mysqlajaxtableeditor.com/Example1.php
Symfony, one of the most popular PHP frameworks around, is sharing several standalone PHP classes (under the Symfony Components website) which can ease the job of a PHP developer.
They don’t require Symfony to be used & can be used with any PHP code.

Currently, 3 classes are ready to be used:

YAML
It parses YAML strings and converts them to PHP arrays. It can also converts PHP arrays to YAML strings.
Event Dispatcher
It’s a good way to make your code more flexible. It’s also a great way to make your code easily extensible by others.
Symfony Event Dispatcher is a PHP library that provides a lightweight implementation of the Observer design pattern.
Dependency Injection
It provides a lightweight and robust Dependency Injection Container for classes that implements the Dependency Injection pattern.

And, 2 new classes are on the way:

  • Templating
  • Request Handler
All the code provided is very well-documented & totally free to use.

Requirements: PHP
Website: http://components.symfony-project.org/
Tuesday, September 8, 2009

Simple & Powerful PHP Image Gallery: Plogger

Plogger is an open source image gallery application, built with PHP-MySQL, that offers a simple usage with powerful features.
The application comes with an attractive admin interface for managing the galleries & can be integrated into any website by adding three lines of PHP code.


Using Plogger, it is possible to create unlimited albums that can include unlimited images. And, uploading the images is a breeze as they can be sent one at a time or as a .zip file in bulk.
Thumbnails are created automatically & there is caching support for faster loading.

Some other features of Plogger:

  • commenting on images (optional)
  • RSS feed on every level (single album, gallery..)
  • an integrated JavaScript slideshow
  • template based theme system
  • valid XHTML output
Also, each gallery has a full XML generator built-in that enables anyone to create widgets in any language.

Requirements: PHP4+, MySQL v3.23+ & GD1.0
Compatibility: All Major Browsers
Website: http://www.plogger.org/
Demo: http://www.plogger.org/demo/
Monday, August 31, 2009

The Complete Joomla Tutorial Pack Free Download

THE COMPLETE JOOMLA TUTORIAL PACKAGE
At Last A Proven Way To Create Professionally Looking Joomla Websites With Ease
Building Websites With Joomla Is Not Easy. Our Complete Joomla Tutorial Package will make you an instant Joomla Professional and you will be able to get your very own Joomla Website up and running!
This Complete Joomla Package will show you with Videos / Ebooks exactly how to install / build / expand and maintain a professional looking Joomla Website. And you don’t even have to worry about the layout because one of our 400 Templates which you CAN EDIT will fit your site the way you want it.

Joomla is the probably the most powerful open source content management systems on the planet today! With The Complete Joomla Tutorial Package its now easy to install, build and run your very own content management system.
  • joomla tutorial No more headaches about INSTALLATION
  • joomla tutorial No more headaches about CONFIGURATION
  • joomla tutorial No more headaches about how to actually USE JOOMLA!
  • joomla tutorial No more headaches about TEMPLATES
  • joomla tutorial No more headaches about where to find MODULE ADDONS
  • No more headaches about CREATING MEMBERSHIP SITES
Our Package Includes:
  • Joomla 1.5 Tutorial Videos
  • 17 Joomla 1.0 Tutorial Videos
  • Create A Membership Site With Joomla Videos
  • 400+ Joomla Templates
  • Top 74 Joomla Add On Modules
  • How To Make A Joomla Template Ebook
  • Joomla Template Maker
Wednesday, July 29, 2009

Free PHP Webmail Application: T-dah

T-dah is a free PHP webmail application which is built from the well-known Uebimiau script & offers a slick interface.
It can be up & running in a few minutes on any PHP (4 or 5) enabled server as no database is required.
The application uses the POP3 protocol & can be configured to use SMTP, PHP mail, Sendmail or Qmail for sending e-mails.
T-dah comes with several modules like:
  • event calendar
  • group chat
  • addressbook
  • folder management
It uses TinyMCE WYSIWYG editor for creating new e-mails, has an integrated search & can be translated into any language with the "language files" support.

Requirements: PHP
Compatibility: All Major Browsers
Website: http://www.tdah.us/
Backend Demo: http://uebimiau.tdah.us/
Backend Demo - User-Pass: User: demo - Pass: demo
Download: http://sourceforge.net/projects/t-dahmail/
Wednesday, May 6, 2009

Free PHP Uptime Monitor Script: phpWatch

As we all experience, every hosting account or server sometimes fails, no matter how good the hosting company is. And, this can be accepted as normal when it is within the limits.
For better reacting to the downtimes, analyzing the health of the web application & the environment it is hosted on, uptime monitoring is a working solution.



phpWatch is a free PHP uptime monitoring script that can watch unlimited number of websites and send notifications via e-mail or SMS (for US phones).
With an Ajaxed interface, new monitors & notifications can be easily configured. And, once the cron job / scheduled task -that pings the servers in desired time intervals- is set, the script is ready to go.
phpWatch also offers an API which lets other applications to query the monitored services, get the statistics and use the notification system for sending SMS and e-mail alerts.

Requirements: PHP, MySQL
Website: http://aaron-rosenfeld.com/2008/08/28/phpwatch-relea...
Demo: http://aaron-rosenfeld.com/phpWatch/demo
Sunday, April 26, 2009

Analyzing PHP Performance: PHP Quick Profile

Firebug is the most popular tool for analyzing HTML, CSS & JavaScript based webpages. Now, there is PHP Quick Profiler (PQP), which can be called as Firebug for PHP.
It is specially focused on analyzing the performance of PHP codes. With a beautiful interface, PQP can:
  • log memory usage
  • display the number & sizes of included files
  • show page execution times
  • log database queries

PHP Quick Profiler is not a plug & play solution as every project may have a totally different structure. But, by following the setup information & the example provided, it is easy to integrate.
To see how functional it is, you can check the demo.

Requirements: No Requirements
Website: http://particletree.com/features/php-quick-profiler/
Demo: http://particletree.com/examples/pqp/
Wednesday, February 25, 2009

40 signs you really are a lousy PHP programmer

1. don't comment your code properly with something like phpDoc
2. don't see the need and/or benefits of a good programming IDE like Zend Studio or Eclipse PDT
3. have never used some form of version control like Subclipse
4. don't adopt some coding & naming standards and general conventions and stick to to them at least throughout the project
5. don't use a consistent methodology
6. don't escape and/or validate properly input or sql queries
7. don't plan your application thoroughly before starting to code
8. don't use test-driven development
9. don't program & test with error reporting on
10. don't see the benefits of a debugger
11. don't refactor your code
12. don't keep the different layers seperated using something like MVC
13. don't know what these stand for: KISS, DRY, MVC, OOP, REST
14. don't return content but echo or print it from your functions or classes
15. have never seen the advantage of unit tests or testing in general
16. return HTML, not data, strings, or objects.
17. hard code messages and configuration parameters
18. don't optimize your sql queries
19. don't use __autoload
20. don't allow intelligent error handling
21. use $_GET instead of $_POST for any destructive actions
22. don't know how to use regular expressions
23. you've never heard of sql injection or cross-site scripting
24. don't allow simple configuration, can be parameters passed to a class’s constructor, set/get methods called later, or constants defined at a runtime.
25. don't understand the benefits and limitations of Object Oriented Programming
26. misuse OOP / everything you write , no matter how small is OOP
27. you think reusable software equals/requires your code to be OOP
28. don't choose intelligent defaults
29. don't have one single configuration file
30. don't want the file contents to be seen, but give it a .inc extension instead of .php
31. don't use a database abstraction layer
32. don't keep it DRY, Don't repeat yourself. If you have to copy and paste or duplicate something your design may be off.
33. don't make a function/class/method do just one thing and don't make them interact.
34. don't try to take advantage of OOP specific features like abstract/interface classes, inheritage polymorphism & access modifiers.
35. don't optimize your application design with established design patterns
36. don't allow your user to define a base directory if you have multiple files and/or directories
37. pollute the global namespace, one option is to prefix the functions in your library with a common string
38. don't allow a table prefix when using database tables
39. use a separate template engine
40. don't take a look at established php frameworks for inspiration, most of them have advanced web dev concepts and good code
Monday, January 26, 2009

PHP File Manager: Simple Directory Listing

Simple Directory Listing is a PHP script that works as an online file manager.
It is only one file, just upload & use, and requires PHP to run.


The script can work in read-only or full mode and can be limited to manage a folder.
Besides the functions of a standard file manager script, it also has a FTP layer that makes it possible to connect to remote hosts.
And, the script has RSS support.
Such scripts are very useful when you want to make "files of a project"  reachable by customers where FTP usage may be limited or seem advanced from the eyes of the customer.
Thursday, January 1, 2009

Free And Ajaxed IMAP Client: Xuheki

Xuheki is an open source IMAP client with an Ajaxed interface.
It looks-feels like a desktop application & supports multiple IMAP servers/identities.


It uses the Net::IMAP::Client Perl module as the IMAP engine & built with DynarchLIB Ajax Toolkit.

Some features of Xuheki:

  • Supports multiple folders with drag’n drop
  • It can stay connected to an IMAP server
  • Interface allows you to do multiple things once
  • Multiple user support
  • Contact list & more..
It requires Perl & MySQL 5 to run.

Requirements: Perl 5.8+, Apache 2+,mod_perl 2+,MySQL 5+
Compatibility: IE can have problems (not well tested)
Website: http://www.xuheki.com/
Download: http://www.xuheki.com/download/
DetectMobileBrowsers.mobi is a website providing a function & information on how to detect mobile browsers.

It can detect:

  • iPhone
  • Opera Mini
  • Android
  • Blackberry

It has an online function generator that guides you to create a personalized function according to "how you want to treat every browser".
P.S. The code is free to be used on non-profit websites.

Requirements: No Requirements
Website: http://detectmobilebrowsers.mobi/
Download: http://detectmobilebrowsers.mobi/#download
Theme Layout 2132 For Wordpress Premium Theme
Wordpress Premium Theme
6 Mb

Monday, December 29, 2008

Joomla!*1.5*Essential*Training

Lynda.com | Joomla!*1.5*Essential*Training
.MOV | 220 Mb | 3 RS links

In Joomla! 1.5 Essential Training, Joseph LeBlanc uses Joomla! to build a small-business website from scratch with no programming at all, from installation to launch. He demonstrates how to create and organize content; add menus, sidebars, and other features; change the look with templates; install plug-ins and extensions; and much more.
Sunday, December 28, 2008

Building Websites with Joomla! 1.5

Building Websites with Joomla! 1.5
PDF | English | March 2008 | 14.8 Mb | RS

The best-selling Joomla! tutorial guide updated for the latest 1.5 release
  • Learn Joomla! 1.5 features
  • Install and customize Joomla! 1.5
  • Configure Joomla! administration
  • Create your own Joomla! templates
  • Extend Joomla! with new components, modules, and plug-ins
Saturday, December 27, 2008

Joomla! Cash Ebook

Joomla! Cash Ebook
PDF | 180 pag. | Oct. 2007 | 9.5 Mb | RS

Chapter 1: Welcome Warriors!
Chapter 2: Creating a Marketing Plan
Chapter 3: Generating Traffic
Chapter 4: Traffic or Log Analysis
Chapter 5: Site Layout and Optimization
Chapter 6: Generating Revenue
Chapter 7: Disaster Recovery
Chapter 8: Small Change