phpbits on Jun 10th, 2008Using session in PHP
Keeping in mind the fact that Internet is a stateless platform and every request for a web page is treated as unique, there is a serious need of a tool to maintain the state. Otherwise, it will be a messy situation to keep track of requests made by a particular user. The good news is […]
phpbits on May 6th, 2008File Uploading in PHP
File uploading is very simple in PHP when comparing to other server side programming languages. File uploading is very useful in most of the situations like uploading user’s photos, uploading csv reports, uploading pdf reports and so on.
Making a simple front end with file browsing box:
<form method="post" enctype="multipart/form-data">
Upload a file
<input name="my_file" type="file" />
<input value="Upload" type="submit" […]
phpbits on Apr 17th, 2008Generating CAPTCHA Image Using PHP
The CAPTCHA concept is very useful to prevent automated registration. If you have enabled gd library, you can create a captcha code for your registration form using PHP.
Consider the following parts of code, name the file as "captcha.php"
session_start();
if(isset($_SESSION[‘captcha’]))
{
unset($_SESSION[‘captcha’]);
}
The above code will start session and clear the old captcha’s session value […]
phpbits on Mar 29th, 2008PHP Interview Questions and Answers
Question: Is PHP a case sensitive programming language?
Answer: PHP is a partially case sensitive programming language. We can use function names, class names in case insensitive manner.
Question: What is mean by LAMP?
Answer: LAMP means combination of Linux, Apache, MySQL and PHP.
Question: How do you get the user’s ip address in PHP?
Answer: Using the server variable: […]
phpbits on Mar 20th, 2008Email validation using PHP regular expression
Regular expression is a wonderful concept, using this we can play with strings in PHP. The practical use of regular expression is:
Email validation
validating domain name
validating post code format etc.
There are two types of regular expression functions:
ereg functions or POSIX extended regular expression function, which is the standard functions for PHP
preg functions or perl Compatible regular […]
phpbits on Mar 12th, 2008Recursive function in PHP
recursive function is a function that calls itself repeatedly for a specified condition.
Here is an example function which calls iteself to perform a tree structure for a category table
Here is the category table:
category_id
parent_id
category_name
1
0
CMS
2
0
Blogs
3
0
Forums
4
0
E-Commerce
5
1
Joomla
6
1
Mambo
7
6
Templates
8
6
Mods/Components
9
4
OSCommerce
10
2
Wordpress
11
10
Themes
12
10
Plugins
<?php echo ‘<select name="category">
<option value=’0‘>Root</option>’;
$allcats = getTree();
foreach($allcats as $key=>$value)
{
echo "<option value=’$key’>$value</option>"
}
echo ‘</select>’;
function getTree($id=0)
{
static $cates = array();
static $times = 0;
$times++;
$result = mysql_query("SELECT category_id,category_name FROM category_table WHERE parent_id=$id ORDER BY category_name");
while($row = mysql_fetch_assoc($result))
{
$cates[$row[‘category_id’]] = str_repeat("| ",$times-1)."|___".$row[‘category_name’];
getTree($row[‘category_id’]);
}
$times—;
return $cates;
} […]
phpbits on Mar 12th, 2008Installing PHP 5 and apache on windows xp.
PHP is best suited for LAMP [Linux, Apache, MySQL and PHP] environment, but we can use in WAMP [Windows, Apache, MySQL and PHP] environment also, here are the options to install & configure php with apache in windows machines.
1] Use WAMP Server or XAMPP server for one click installation, no need for configuration.
2] Manually install […]
phpbits on Mar 10th, 2008Introduction to PHP
PHP stands for "Hypertext Preprocessor" [recursive acronym], a very popular open source server side scripting language allows users to develop rich, effective and scallable web portals and web applications. It was created by "Rasmus Lerdorf". It can be run under IIS, apache and other popular web servers.
Sites developed using PHP:
feedburner
istockphoto
yousendit
meebo
techcrunch
