From The Blog

CakePHP: Get Client's IP Address

27 October 2012, in

in CakePHP 1.x

Through the RequestHandler Component:

RequestHandlerComponent::getClientIp();

in CakePHP 2.x

RequestHandler::getClientIp() is deprecated, so you can use the CakeRequest object

$this->request->clientIp();

 

of course you can still use the server variable   $_SERVER['REMOTE_ADDR']



Post a Comment

PHP: client's IP address

27 October 2012, in

The IP Address of the client who sent HTTP request is stored in the server variable:

$_SERVER['REMOTE_ADDR'];



Post a Comment

PHP: parsing all the XML including CDATA

22 October 2012, in

It is common when writing XML files to put data like HTML and XML in CDATA to avoid mixing between XML tags and content tags

but whatever comes inside CDATA is ignored, and not parsed

so to read which inside it when parsing XML add the attribute "LIBXML_NOCDATA" like this:

$xml = simplexml_load_file('xmlfile', NULL, LIBXML_NOCDATA);


Post a Comment

PHP: redirect to referrer page

18 October 2012, in

In PHP to redirect to another page you use:

header("location: http://www.example.com");

If we wanted to redirect to the referrer page we use like that:

header('Location: '.$_SERVER['HTTP_REFERER']);



Post a Comment

PHP: Calculate result of a mathematical expression given in a string

10 September 2012, in

How to calculate the result of a mathematical expression given as a string:

function calc_string( $mathString )
{
$cf_DoCalc = create_function("", "return (" . $mathString . ");" );
return $cf_DoCalc();
}

echo "result is: "calc_string("2+25*3");

//result is: 77



Post a Comment

PHP: Check if cURL is loaded or not

4 September 2012, in
To check client URL (cURL) is enabled or not you can simply:

if  (in_array  ('curl', get_loaded_extensions())) {
return true;
}
else{
return false;
}
Tags: 


Post a Comment

Strip HTML tags and it's contents too

8 August 2012, in

To strip tags we can use the php function strip_tags($str) but it will return the content of the tags too,

How to strip html tags and remove it's contents too ?



Post a Comment

are these functions identical

5 July 2012, in

Let's see this question:

//Assume

function example1(){

echo 'example 1';

}

//,and

function example2(){

echo 'example 2';

}

//True or False

var_dump( ( example1() ==  example2() ) );

This will result to TRUE, but why?



Post a Comment

Installing PHP5 and Apache on Ubuntu

20 June 2012, in

First, you'll want to add the extra repositories to Ubuntu's sources.list file.

From a command shell, you will run the following commands:

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart



Post a Comment

Simple crawling using cURL

2 June 2012, in

example of simple crawling of web pages using client URL (cURL)

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.example-url.com");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content= curl_exec($curl);
curl_close($curl);

 

var_dump($content);  //content being crawled



Post a Comment

Pages