How do i check if a string contains a specific number?

Dear Experts

This script wont work for some reason...

$ipaddress = gethostbyname($domain);

if ($ipaddress == "127.0.0.1") { $status == "offline";}
else { $status == "online"; }

echo $status;


I know the $ipaddress is 127.0.0.1 but nothing echos

Thanks in advance
maccaj51Asked:
Who is Participating?
 
Pratima PharandeConnect With a Mentor Commented:
if ($ipaddress == "127.0.0.1") { $status = "offline";}
else { $status = "online"; }

echo $status;

you are using "==" for assignmetn change it as above
 $status = "offline";
0
 
Pratima PharandeCommented:
if ($ipaddress == "127.0.0.1") { $status = "offline";}
else { $status = "online"; }

echo $status;
0
 
GnarfCommented:
Are you quite sure the ip address returned in fact is 127.0.0.1? Either, gethostbyname will return null (misspelling of the host name) or the IP adress retuirned is the one assigned to your computer. In case of a company network this may one starting with  192.168.

To find out:
Check if $ipaddress is null
If it is not, use the echo command or something similar to print it out
Enclose the output into special characters, lets say the pipe sign. This will help you detect leading or trailing white spaces

HTH
Gnarf
0
 
maccaj51Author Commented:
pratima_mcs GREAT SPOT!!!

Many Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.