So I'm making a page for one of my web sites that scans the visitors ports (just a few specific ones, not ALL) and tells them if they have any open. Now I made up the code and it worked great. Now instead of having the same chunk of code all over my script, I tried to make my own subroutine so I could just call it from all over. But since I did that, it now gives me an error of type 0, which means it couldn't even try to connect to the host, before it got an error. I can't figure it out at all?
OK, I am very much a beginer at PHP. It appears to work fine if you add quotes around the first argument (maybe because the fsockopen's first argument is a string? (anybody?)). Also slightly modifed your syntax. See below. On my PC, the output was: "Closed 9 " when trying port 22, but trying port 80, the output was "Open"
Why do you keep posting then deleting your posts? Anyway most of the changes you made are no change. I don't think adding the quotes is going to make a difference because the code worked fine without them when it wasn't in its own function. Nope, just tested, no change.
Sorry, editing the post. Well, all I can say is that the function works on my pc as written. As I said, I am a beginer at PHP too. I will add though that the code you posted does not work for me. I get the same error as you mentioned "Closed 0"
The code works perfect for me when I insert it directly into my page. But when I try to encapsulate it into a function, it stops working and I have no clue why.
I tried that and it had no effect. I don't think my problem is calling my function, the problem is somehow that the script can't great a new socket from within the function. I do already get a result from the function, its just an error code from the socket. And I thought you didn't NEED a return if you didn't need the result of the function.
What is the value you are passing to REMOTE_ADDR? Have you tried hard coding a value to test the function? Also, what scope does the variable REMOTE_ADDR have within the function? Is PHP like shell where a variable within a function has global scope? or is it a more limited scope?
$remote_addr is a system variable, it is already defined. I never pass anything to it, and it is always equal to the visitors IP address. Also this chunk of code works perfectly fine when its not in my function, only when it is in, does it give me a connection error from the fopensocket.
I got this all figured out on another forum. I thought $REMOTE_ADDR was global because outside of functions you can access it no problem. But to use it in functions, you have to make it a global, which is what i did and now it works fine. Its strange though. Thats why it worked when it wasn't in a function but didn't when it was in one.