Currently Browsing: PHP/MySQL
Jan 22, 2010
Get IP Address in PHP
Many times we need the IP Address of the User visiting our website in our Application.
I am listing here the method to get the User IP Address, hope it might be useful to many of you.
//function for getting IP
//start
function getuserip()
{
if (isset($_SERVER))
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
...
read more
Jan 21, 2010
Assign PHP Array to Javascript Array
I am describing here a very useful method for getting the values of a PHP array in JavaScript.
For this we need to assign the PHP array values to a array in JavaScript.
<?php
$a = array('A','B','C');
?>
<html>
<head>
<title>Assign PHP Array to Javascript Array</title>
<script language="javascript">
function showValues(){
var a=new Array;
<?php
for($i=0;$i<count($a);...
read more
Jan 20, 2010
Copy Directory
I am listing here the method to copy full Directories with all sub-directories and files.
<?php
$source = 'f1'; //folder name
$target = 'f2'; //folder name , if target folder does not exists, it will be created
//echo 'src->'.$source.'<br/>';
//echo 'tar->'.$target.'<br/>';
if(is_dir($source))
{
full_copy($source,$target);
echo 'Folder copied';
}
else
{
echo 'Not copied';
}
function...
read more
Jan 14, 2010
Display numeric in words
I hope this script will be very useful to all of you who are working in PHP.
Actually this is a kind of small and useful project.
I was asked to develop a script for displaying sum total in words in one of my interviews, at that time I could not complete this script.
So I decided to complete it, and so I developed it, which I am sharing with you all.
This script can display numeric to words upto millions...
read more
Jan 14, 2010
encode and decode string with base64
Many use encoding and decoding on daily basis including me, so once I made a simple script for encoding and decoding the input string with base64.
base64.txt
Instruction:
1) Download the file and save the text file as PHP file.
2) Place the file in your root directory.
3) Execute the file from browser.
4) Enter the string to and decode or encode it by selecting the options.
read more
Jan 14, 2010
ASCII example
You might have visited many sites related to songs or movies, you might have noticed that the searching is in Alphabetical order, so what will you do if you want such listing, write all the characters from A to Z ?.
There is an easy way for implementing this in PHP.
We can use function ord() and chr().
ord – Return ASCII value of character.
chr – Return a specific character.
I am attaching a simple...
read more
Jan 14, 2010
Set Default Time Zone
Some of you may have faced the issue for converting timezone for displaying date and time.
Means suppose you want to display current time in India, than what will you do for that.
You might have added 5 hours and 30 minutes to the default time.
But there is already a functionality for that in PHP.
You can switch the timezone as per your requirement.
For example,
You get default time by
<?php echo...
read more
Jan 13, 2010
List Date Difference
Some of you might have come across the requirement for displaying all the dates between give two dates, especially for drop down listing of dates.
I have developed a sample code for getting all date ocurrences between give two dates.
<?php
$fromDate = "01/01/2009"; //format mm/dd/yyyy
$toDate = "01/25/2010"; //format mm/dd/yyyy
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS...
read more
