DtDNS: PHP cURL 1: Difference between revisions
no edit summary
(New page: {{Nav DtDNS}} '''''Introduction''''' On the previous page I explained why you should never enable external includes in php.ini there is a safer way to download external pages and that is ...) |
Upazixorys (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
=[http://egyworene.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]= | |||
{{Nav DtDNS}} | {{Nav DtDNS}} | ||
'''''Introduction''''' | '''''Introduction''''' | ||
Line 12: | Line 13: | ||
Extracting the IP address is performed using a regex since we are specifically targeting information we want and discarding any other page content means any harmful code will never be run. | Extracting the IP address is performed using a regex since we are specifically targeting information we want and discarding any other page content means any harmful code will never be run. | ||
{|cellspacing= | {|cellspacing="6" | ||
|- | |- | ||
| | | | ||
<pre> | |||
<?php | |||
$ch=curl_init(); | $ch=curl_init(); | ||
curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com'); | curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com'); | ||
Line 30: | Line 31: | ||
else{ | else{ | ||
// Extract IP address | // Extract IP address | ||
if(preg_match( | if(preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $buffer, $ipmatch)){ | ||
$ip = $ipmatch[0]; // Save IP to variable | $ip = $ipmatch[0]; // Save IP to variable | ||
} | } | ||
} | } | ||
print $ip; // Test code | print $ip; // Test code | ||
? | ?> | ||
</pre> | |||
| | | | ||
* Initialize Curl and save memory location in variable $ch | * Initialize Curl and save memory location in variable $ch | ||
Line 58: | Line 59: | ||
|- | |- | ||
| | | | ||
<pre> | |||
<?php | |||
$ch=curl_init(); | $ch=curl_init(); | ||
curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com'); | curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com'); | ||
Line 73: | Line 74: | ||
else{ | else{ | ||
// Extract IP address | // Extract IP address | ||
if(preg_match( | if(preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $buffer, $ipmatch)){ | ||
$ip = $ipmatch[0]; // Save IP to variable | $ip = $ipmatch[0]; // Save IP to variable | ||
} | } | ||
} | } | ||
print $ip; // Test code | print $ip; // Test code | ||
? | ?> | ||
</pre> | |||
| | | | ||
'''''Run Test 1'':''' | '''''Run Test 1'':''' | ||
* Run servers | * Run servers | ||
* Type ''' | * Type '''<nowiki>http:</nowiki>//localhost/dtdns_test_1.php''' into your browser | ||
* Result: Returns your '''current'''IP address for example | * Result: Returns your '''current'''IP address for example | ||
<pre> | |||
179.79.934.216 | 179.79.934.216 | ||
</pre> | |||
|} | |} | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
Line 99: | Line 100: | ||
|- | |- | ||
| | | | ||
<pre> | |||
COLOR B0 | COLOR B0 | ||
@echo off | @echo off | ||
Line 113: | Line 114: | ||
popd | popd | ||
EXIT | EXIT | ||
</pre> | |||
| | | | ||
'''''Run Test 2'':''' | '''''Run Test 2'':''' | ||
Line 119: | Line 120: | ||
* Double click on Run_dtdns_test_1.bat | * Double click on Run_dtdns_test_1.bat | ||
* Result: Returns your '''current''' IP address for example | * Result: Returns your '''current''' IP address for example | ||
<pre> | |||
179.79.934.216Press any key to continue . . . | 179.79.934.216Press any key to continue . . . | ||
</pre> | |||
|} | |} | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' |