Archive for "PHP"
Dec03Creating a new php functionality page in iLister, the business classifieds system
Here’s the step by step guide to create a new functionality page in iLister.
Let’s say we wanted to create a new small enquiry form at the http://www.yoursite.com/contact_us. For this to make happen we will create a new ContactUs handler to process the form values and will place it under miscellaneous. Following are the steps required. Click to continue »
Dec02To check in a smarty template if it was the last page of the page results
Here’s a method to check in a smarty template if it was the last page of page results.
{if $listings.current_page gte ($listings.total / $results_per_page)|ceil}
True
{else}
False
{/if}
where $listings.current_page is the current page user is on, $listings.total is the number of totals results and $results_per_page is the number of listings or rows that are displayed on each page. “gte” is >= operator and |ceil as the mathematical modifier which returns next lowest integer.
Nov28Formatting date in a php smarty template
The date string can be formatted in a smarty template like this:
$payment.creation_date|date_format:"%d-%m-%Y"
where creation_date is an element of $payment array.
Nov27An advanced HTML to PDF conversion using ezpdf php class
Posting a link to the working example of HTML Form to PDF using “ezpdf” php class. I added some code to this class in order to create more advanced HTML tables cells with borders as shown in the output PDF document. Click to continue »
Oct15A simple way to debug a php application in production mode
How to debug a live website built in php?
Here’s a basic, simple and custom method i usually use to debug live or production web applications (web sites).
First of all i place the following lines of code in a config.php or somewhere so it is loaded in all targeted pages of the website. Click to continue »
Sep02Re-sizing image by width using php
A simple yet very useful function to re-size image by maximum width while keeping width and height in proportion. You just need to pass the maximum width allowed to this function and this function will return you an array containing new width and height. Click to continue »
Jun06Creating rss feed dynamically and merging it with another rss feed
Recently i generated a rss feed from business listings for one of my client’s website. Also, i merged this listings feed into client’s existing blog rss feed. Here’s how i did it. Click to continue »
Mar04Validating php multiple-value checkbox form element with javascript
In php a multiple-value form element such as checkbox is named suffixed with a set of square brackets. For example,
My commonly used colors are:
<form action="index.php" name="myform" method="post" onsubmit="return validate_form();"> <input type="checkbox" name="colors[]" value="red" /> <input type="checkbox" name="colors[]" value="green" /> <input type="checkbox" name="colors[]" value="blue" />
To validate these kind of checkboxes’ using javascript is little tricky. While on the other hand, having a single checkbox without multiple-value selection it would have been straight forward, something like this:
function validate_form() {
// considering form element <input type="checkbox" name="color" value="red" />
if(true==document.myform.color.checked) {
//checked, ok. Let it go.
} else {
//not checked, stop it.
}
}
Considering multiple-value selection the document.myform[].color.checked or document.myform[].color.length would throw javasript error. To make it work as expected the javascript code in your validate_form function will need some changes. Here we go.
function validate_form() {
var flag = false; //at the initial state we assume that nothing is checked
for(var i=0; i < eval('document.myform.elements["colors[]"].length') ; i++) {
if(true === eval('document.myform.elements["colors[]"]['+i+'].checked')) {
flag=true; //at least some thing is checked, we are good to let them go past this check
/*
//Hint: As a separated implementation somewhere though, if you wanted you could trigger the checked/un-checked status of your checkbox like the following:
//document.myform.elements["colors[]"][i].checked = false; //or true etc.
*/
}
}
if(true==flag) {
//checked (at least something), ok. Let it go.
//Hint: if you wanted that all your checkbox should have been checked check for the value of i variable
} else {
//not checked, stop it.
}
}
In line 3 of modified function above we use powerful eval function to evaluate the string passed to it. The eval function accepts any valid piece of javascript code and returns output value. In the passed code string to eval function we write normal (parent to child access) algorithm to access the elements property (and its element) of myform object which is a property of our web page (document) object.
Feb18Choosing a business listing directory script written in php
I got a new client today who wanted a brand new website equipped with business listing directory feature. According to him, the script should be in PHP, does not cost much and meets all requirements of a basic business listing directory. It should support multiple image uploads for a listing, be able to do rating(optional) and reviews, supports (paypal IPN) payment method, provides google map locator facility and finally be equipped with small CMS to create some content/article pages, that’s all. Click to continue »
Feb10phpMyAdmin PHP Code Injection Exploit attempt on my server
This morning, when i checked my Give Back India site’s access log i found some scripts/setup.php request attempts. In fact, not ‘some’ but hundreds of them. All requests were made targeting phpMyAdmin’ installations on my server. Here are a few of them: Click to continue »





