game.onenall.com,play free game online game.onenall.com,play free game online game.onenall.com,play free game online game.onenall.com,play free game online game.onenall.com,play free game online game.onenall.com,play free game online game.onenall.com,play free game online game.onenall.com,play free game online

how to chk ip in a ip range using php

Okay, so I put all my IP ranges in the database and wrote a function which takes an IP as input and checks the database to see if the IP is in the listed ranges. It returns TRUE if the IP is not in any of the ranges. The table where I put the ranges looks like:

Code:

+-----+-----------------+-----------------+
| ID  | StartIP         | EndIP           |
+-----+-----------------+-----------------+
|   1 | 123.123.123.123 | 123.123.200.200 |
|   2 | 124.129.0.123   | 124.129.200.200 |
|   3 | 231.160.124.1   | 231.255.255.255 |
+-----+-----------------+-----------------+
The PHP function which I wrote to do the lookup/check is:
PHP Code:
function check_ip($IP)  {  $IP = ip2long($IP);  $result = mysql_query("SELECT * FROM IPRangeTable");  while($row = mysql_fetch_array($result))  {  $StartIP = ip2long($row['StartIP']);  $EndIP   = ip2long($row['EndIP']);  if ($IP >= $StartIP && $IP <= $EndIP)  {  return FALSE;  break;  }  }  return TRUE;  }
thanks

php function to formate mysql date

php tutorial

hi today i am writting simple php function to formate the date from mysql data

<?

//first formate defining
define(‘DATE_FORMAT’, ‘d/m/Y’);  // this is used for date()

//now writing the function to formate the date

function tep_date_short_mdy($raw_date)

{

$date=strtotime($raw_date);

$daylam=date(DATE_FORMAT, $date);

// 05/16/2000

$daylam1=explode(‘/’,$daylam);

$day1=$daylam1[1];

$month1=$daylam1[0];

$year1=$daylam1[2];

$dayfinal=$month1.’/’.$day1.’/’.$year1;

return $dayfinal;

}

?>

isn’t it is simple one to formate the date which is getting from mysql database.

thanks

mrphpguru

PHP Class for Date Time calculations





Performing data/time calculation is basic requirement in any programming project. No serious application can hide from it, so thankfully PHP itself comes with some very useful data/time functions. But, I feel that those PHP date/time functions are probably great for data/time display and formatting, but not so much for calculating for things like the beginning/end of the week, the number of seconds between two dates etc.

Again thankfully, after a visit to phpclasses.org, I found a nifty little class written by Steve Powell (way back in 2004) called DateClass which did what I wanted. Unfortunately, the documentation was only a class reference sheet, and doesn’t come with any examples to quickly get things going.

The DateClass package actually contains 2 individual classes. One for manipulating dates and the other for manipulating date spans. This post will only cover the actual DateClass object. I’ll post the followup in Part 2 for the DateSpanClass object soon.

Let’s get cracking.

Example 1: Display the current date and time.

<?php
// include the DateClass class
include('dateclass.php');

// initiate the class
$dc = new DateClass();

// output to string
echo $dc->ToString();
?>
Yes, I know, this does the same as calling date()function in PHP.

echo date('Y-m-d H:i:s');
So, why should you use such a long winded method? Well, it’s the other methods in the DateClass class that we’re interested in.

The class comes with the standard calls you’ll find equivalent from PHP, such as, Year(), Month(), Day(), Hours(), Minutes(), Seconds(), Timestamp(), etc. So they’re all pretty self explanatory. Instead, let’s look at some of the more interesting methods.

Example 2: Find the beginning and end of the week.
<?php
// include the DateClass class
include('dateclass.php');

// initiate the class
$dc = new DateClass();

// calling BOW() will return another DateClass object
// for beginning of the week.
$bow = $dc->BOW();

// output the datetime for the beginning of this week.
echo $bow->ToString();

// calling EOW() will return me another DateClass object
// for end of the week
$eow = $dc->EOW();

// output the datetime
echo $eow->ToString();

// destroy the DateClass objects
$dc = "";
$bow = "";
$eow = "";
?>
I think you get the idea. The class also includes methods for:
  • BOM() and EOM() – Beginning and end of the month
  • BOQ() and EOQ() – Beginning and end of the quarter
  • BOY() and EOY() – Beginning and end of the year
  • Quarter() – which returns the calendar quarter (1-4) the current date value of class is in.
Example 3: Calculating dates 2 days forward and then 2 months back Lastly, let’s look at the date calculation using the Add() method.
<?php
include ('dateclass.php');

// initiate the class
$dc = new DateClass();

// add 2 days to the current date
$nd = $dc->Add('days',2);

// subtract 2 months to the previous calculated date
$nd = $dc->Add('months',-2);

// output the new datetime
echo $nd->ToString();
?>
Although using DateClass is a bit more verbose than say, using strtotime() approach, I find this more intuitive and easier to understand. But that’s just me.

Coming up in my next post, I’ll cover what the DateSpanClass can do, and how to return results like the number of whatever (days, months, hours, even weekdays) between 2 dates. Watch out for it.

source :php classs

strpos function to check character in string using php





strpos function to check character in string using php

suppose i would like to find : in string so chk this out

$username = ’mrphpguru:aphp coder’;
$pos = strpos($username, ”!”);
if ($pos == -1)
{
print Please ‘don’t put : in your usernames’;
}
else
{
print ’No special character in the string.Thanks’;
}

So using strpos function we can find a character in a string using php function strpos.

thanks

mrphpguru

get random value and key from array uisng php





get random value and key from array uisng php

I have written a function to get the set of random key and value from the array.

function random_array_element(&$a){
mt_srand((double)microtime()*1000000);
// get all array keys:
$k = array_keys($a);
//print_r($k);
// find a random array key:
$r = mt_rand(0, count($k)-1);
$rk = $k[$r];
// return the random key (if exists):
$Value = isset($a[$rk]) ? $a[$rk] : ”;
if(!empty($Value))
{
$kevalueSet = “$rk:$Value”;
return $kevalueSet;
}
else
{
//call the same function or echo
}
}

it will return Key and value set randomly from array like

135:http://humboldt.craigslist.org

so you can explode the above value an get the Array Key and Respective value randomly using php

thanks

Download file or web page using PHP cURL



Download file or web page using PHP cURL

I am discussion how to use cURL function of php to download  a web page and save it .

A typical PHP cURL usage follows the following sequence of steps.

curl_init – Initializes the session and returns a cURL handle which can be passed to other cURL functions.

curl_opt – This is the main work horse of cURL library. This function is called multiple times and specifies what we want the cURL library to do.

curl_exec – Executes a cURL session.

curl_close – Closes the current cURL session.

Below are some examples which should make the working of cURL more clearer.

The below PHP code uses cURL to download Google’s RSS feed.

<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'http://news.google.com/news?hl=en&topic=t&output=rss');
/**
* Create a new file
*/
$fp = fopen('rss.xml', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>

SO enjoy php cURL function to save remote file.

thanks



Submitting forms using PHP cURL

To submit forms using cURL, we need to follow the below steps:

Prepare the data to be posted
Connect to the remote URL
Post (submit) the data
Fetch response and display it to the user

Prepare data to be posted

<?php
$data = array();
$data['first_name'] = 'Jatinder';
$data['last_name'] = 'Thind';
$data['password'] = 'secret';
$data['email'] = 'mrrrr@playfreegamesonly.com';
?>
So now we need to make the post data encodeing we will use php encoding to do so.Below function will do the same.
<?php
$post_str = '';
foreach($data as $key=>$val) {
	$post_str .= $key.'='.urlencode($val).'&';
}
$post_str = substr($post_str, 0, -1);
?>

Connect to the remote URL

Below is the function to connect to the remote server using curl
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/form-handler.php' );
?>

Post (submit) the form data

First we instruct cURL to a regular HTTP POST.
<?php
curl_setopt($ch, CURLOPT_POST, TRUE);
?>

Next we tell cURL which data to send in the HTTP POST.

<?php
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
?>

Execute request and fetch the response

<?php
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

So using above function we can submit form to remote server or site using curl
thanks

duplicate coming on post





duplicate
coming on post nl2br function

can anyone help with this please, im using this linked to a textbox so that people can enter info and it will save to a database whilst when viewed outside of a textbox it will show normally in html. the problem is that if someone tries to edit there entry then it shows with (
) on the end of the lines. this is kind of a problem because the people using my form wont have a clue what the hell is going on. is there a way to remove this from the textbox?

second problem with it. if you then resubmit the info from the textbox then it duplicates the (
) and causes there to be 2 trailing
‘s on the end of each line…

can anyone help with this please… :confused:

how to sort php array highest to lowest php

how to sort php array highest to lowest php

Hi i want to sort php array from highest to lowest for that simple problem i used sort and rsort together..

$ides = explode(‘:’,$_GET[id]);
//using explode i am creating array

sort($resumeId);

rsort($resumeId);

So result will a array with highest on top and lowest on last..

thanks

mrphpguru

how to disable cache form browser using php

How to disable cache form browser using php
Using header function of the php we can disable the browser cache.

Browser cache

header (‘Expires: Mon, 14 Oct 2002 05:00:00 GMT’);

setting the date in past so that browser detect that page has generated in past..


<?
/**
* Disable any caching by the browserfunction disable_browser_cache()
{
@ header ('Expires: Mon, 14 Oct 2002 05:00:00 GMT'); // Date in the past
@ header ('Last-Modified: ' . gmdate ("D, d M Y H:i:s") . ' GMT'); // Always modified
@ header ('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP 1.1
@ header ('Cache-Control: post-check=0, pre-check=0', false);
@ header ('Pragma: no-cache'); // HTTP 1.0
}

//how to call this function

// Disable any caching by the browser
disable_browser_cache();
?>

so u are seing the above function to disable the cache from the browser using php.

so u can see using header function of php we can disable browser cache…

mrphpguru