Hi....I am a noob at PHP....and I need help with a PHP Script
I found this example on a website and i wanted to know if anybody could write this in PHP....and not need lnyx or bash to use it!!!!
Here is the script
#! /bin/bash
exip=`lynx -dump http://www.whatismyip.com | head -n 2`
echo "$exip"
Thanks in return.......
Need help writing a simple Php
Moderator: General Moderators
Re: Need help writing a simple Php
This can be hugely refined but:
Before anyone slams me for the code, I grabbed it from a google search for "example Curl Php script".
That will return the entire page as $result, after which chopping it up into the bits you want is just a matter of string slicing and so on. If it's a particular value you want then consider using preg_match and regex to find it.
If you're simply after a script that will show your box IP:
You could find this pretty quickly with google too, try searching "PHP what's server IP".
Code: Select all
<?php
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://www.whatismyip.com/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);
?>
That will return the entire page as $result, after which chopping it up into the bits you want is just a matter of string slicing and so on. If it's a particular value you want then consider using preg_match and regex to find it.
If you're simply after a script that will show your box IP:
Code: Select all
<?php
echo $_SERVER['SERVER_ADDR'];
?>Re: Need help writing a simple Php
The Bottom one I've tried before.........I't returned 127.0.0.1 (definetly not right!!!)SeaJones wrote:This can be hugely refined but:
Before anyone slams me for the code, I grabbed it from a google search for "example Curl Php script".Code: Select all
<?php $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, "http://www.whatismyip.com/"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); ?>
That will return the entire page as $result, after which chopping it up into the bits you want is just a matter of string slicing and so on. If it's a particular value you want then consider using preg_match and regex to find it.
If you're simply after a script that will show your box IP:
You could find this pretty quickly with google too, try searching "PHP what's server IP".Code: Select all
<?php echo $_SERVER['SERVER_ADDR']; ?>
The reason I need the script is i am running a webserver from home...and i have a dynamic IP and i am behind a router....so the script is supposed to return my outside ip......The Curl one worked....not in the way i wanted it to.....but it serves it's purpose.......
Thanks for the Help SeaJones!!!!!