Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

getting Notice: Undefined variable: ip how do I do this correctly?

Posted on 2008-10-01
4
Medium Priority
?
391 Views
Last Modified: 2013-12-12
I have a probably simple issue..
I have all errors on and want them on. but I am getting an error message:
Notice: Undefined variable: ip in C:\Program Files\Zend\Apache2\htdocs\babyearth_testing\testip.php on line 65

Not sure why??
<?php
$ip = (isset($_SERVER["HTTP_CLIENT_IP"])) ? $_SERVER["HTTP_CLIENT_IP"] : $_SERVER["REMOTE_ADDR"];
 
echo "<br> Your IP recorded is: $ip";
?>

Open in new window

0
Comment
Question by:jbrashear72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22616336
try:
<?php
$ip = (isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "EMPTY") );
 
echo "<br> Your IP recorded is: $ip";
?>

Open in new window

0
 
LVL 3

Author Comment

by:jbrashear72
ID: 22616600
That did it. Can you explain what corrected it?
I need to understand so if I load a variable I don't get the error.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22616733
you have:
$ip = (isset($_SERVER["HTTP_CLIENT_IP"])) ?

but the value for $ip should be the value of the whole expression on the right. You are closing the first parenthesis immediately before the question mark, but you really need to close it at the very end of the statement.
$ip = (isset($_SERVER["HTTP_CLIENT_IP"]) ? ... : ... );

furthermore, you also need to make sure that
$_SERVER["REMOTE_ADDR"]

isset.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question