Posts Tagged ‘PHP

Oct
15
A simple way to debug a php application in production mode

A simple way to debug a php application in production modeHow 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 »

Tags : , , , ,

Mar
04
Validating 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.

Tags : , , , , , , ,

Feb
18
Choosing 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 »

Tags : , , , ,

Feb
08
Converting a text string into comma separated words

Today, i was looking at some old code of mine to find something when i found this little but useful piece of code which i had written for one of my old projects (and of course when i didn’t had this blog created yet). The idea was to create comma separated words from a string, something like, creating meta keywords from a piece of information (such as meta description). Click to continue »

Tags : , , , , ,

Dec
09
Setting up a catch-all email forwarder and parsing emails using php

In one of my ongoing projects i had to set up a “catch-all” email parsing script. Here’s how it came out to be.

What is catch-all?

In the context of emails, “catch-all” refers to a destination to which all incoming emails with in-correct email addresses are delivered or forwarded. As a destination, you can set either an email or a script on your server which captures such emails and save them in to your local database or files. Click to continue »

Tags : , , , ,

Oct
19
Getting current page url and title for social network sharing in WordPress

Today i added a few social network sharing buttons i.e. facebook, twitter, delicious, myspace etc. to the right side column of this very blog.  To make it work as desired I had to do some extra bit of effort to create respective urls and titles for sharing. Click to continue »

Tags : , , , , , ,

Sep
29
Form DOM element not recognized (created) in ajax form in IE when placed with end tag missing

Skipping a form end tag </form> costed me almost a day (i had to go to bed abandoning the fixing for some time though;)). I had been using ajaxForm with jQuery to submit ajax form which was placed on a popup dialog box opened through ajax. The form worked well in Mozilla Firefox, Google Chrome, Safari but did not work in Internet Explorer 7 & 8 (IE7 & IE8 ; i didn’t test in other versions of IE but perhaps they would not work either). The IE simply would not create the <form> tag at all so if you try to alert $(“#formID”).length it would return always 0(zero). It started to work fine (in IE) when i placed </form> to mark the end of the form (i know it was a mistake to not to place it there though). Click to continue »

Tags : , , , , , , ,

May
14
A note on setting up execution memory and time limits for php scripts

When executing large amount of data through php scripts it is common facing errors like “Fatal error: Maximum execution time of 300 seconds exceeded..”. Also, sometimes uploading large files through php scripts you might face errors like “The uploaded file exceeds the upload_max_filesize directive in php.ini..” etc. etc.. Click to continue »

Tags : , , , , , , , , ,

Apr
16
Better way to write php code – part 2

With the help of an example i would explain a very common but erroneous approach new php developers seem to follow (i have seen some ‘old’ ones repeating the same error though). Here it is, Click to continue »

Tags : , , , , , , , , ,

Apr
03
Better way to write php code – part 1

A few tips on writing php code that can save a php developer a lot of future troubles and “huffs and puffs” occurring due to different php compiler settings, changing of hosting environment etc. Here is first one. Click to continue »

Tags : , , , ,

Freelance Jobs