Doing some work on a site for someone, and he asked me what this line does, and it's just beyond my PHP skills at this point. Can someone explain what this line actually means, and why it would be there? Is literally the only line in the file, except for the php open tag and some remarks that don't explain it (real IP replaced by x's):
Is the real IP perchance the site owner’s IP address? The first thing that comes to mind is that the code in question is intended to execute for everyone except the site owner. If there doesn't happen to be any code, is it possible this bit is left over from some earlier stage in the site’s development, and they left the empty envelope in case someone in the future wanted to use it again?
gmac6791
8:37 pm on Jan 19, 2021 (gmt 0)
The owner says the IP resolves to somewhere in India, and he did have a developer from that country working on the site at one time. I was thinking as well that it's something do to with that person's work, and might not be needed. Just want to be sure before I make that call.
JorgeV
9:52 pm on Jan 19, 2021 (gmt 0)
Hello,
This line of code means that if the IP address is not xxx.xx.x.xxx to "quit" the current "block".
What's the name of the file in which this line appears?
Let's say it's "is_myself.php" , then it can be used this way:
// some code executed for everybody.
require('is_myself.php');
// some code to be executed only if this is the dev. (myself = ip == xxx.xx.x.xxx)
This can also be used within a function.
The advantage, is that, if you want to change the IP address, you just edit the is_myself.php. Or if you want to add other tests, like for example, testing the logged user, etc...
gmac6791
11:07 pm on Jan 19, 2021 (gmt 0)
Aha, understood! Thanks JorgeV!
w3dk
11:15 pm on Jan 19, 2021 (gmt 0)
...the code in question is intended to execute for everyone except the site owner.
Looks more like the opposite.
Probably for debugging, as @JorgeV suggests. But could also be a backdoor of unsavoury intent (unlikely)!
lucy24
4:20 am on Jan 20, 2021 (gmt 0)
Looks more like the opposite.
Dang. I entirely overlooked the significant return at the end of the line.
Haha. You’re right: that sheds no light whatsoever :)
:: idly thinking that if this were the kind of site that did casual polls, I would ask how many comment lines people use before switching from // blahblah on every line to /* blahblah */ enfolding the whole thing ::
JorgeV
9:56 pm on Jan 20, 2021 (gmt 0)
Hello,
Just to add.
Here is the proper way to have multi-line comments. This is the standard and good practice. Code editors are formatting comments like that, by default. This is a legacy of programming languages like C/C++.
/** * * * */
This kind of formatting is also the one looked for, when you have automation scripts which are parsing source code.
Using // on every line, also has an advantage. You can comment a large section of code, by using /* */ without minding about internal comments.
If internal comments are /* */, and you want to comment the large block, you'll have problem with opening and closing tags .
gmac6791
11:57 pm on Jan 20, 2021 (gmt 0)
Yes. To clarify, I'm not the one who wrote the code in this file, but I do know proper commenting protocols. :)