1

I created a script to search for, copy, compress and send files from a Cliet/Local PC to a Master PC.

The files need to be identified on the master PC. the format is

`UUID.IP.crc.gz`

So the PC running the script (Local), I need that PC's IP address.

I've tried using $_SERVER["REMOTE_ADDR"] and $_SERVER['SERVER_ADDR'], but none of those where defined.

Notice: Undefined index: SERVER_ADDR in C:\wamp\www\postEnginInstruction\properties.php on line 9 and the same for "REMOTE_ADDR"

What am I doing wrong?

morne
  • 4,035
  • 9
  • 50
  • 96

2 Answers2

2

If you use php with a CRON, there is no HTTP request nor server, you just use it as a script language. So you can't access $_SERVER value.

You have to use then a command like ipconfig (or ifconfig on linux) with the exec command in PHP.

Edit : look here also for easier solutions : How do I find my server's IP address in PHP(CLI)

Community
  • 1
  • 1
ôkio
  • 1,772
  • 1
  • 15
  • 16
1

One thing you can do to 'create' an HTTP request is schedule a curl-command to activate your PHP script:

curl http://your.server/path/to/your/scheduledScript.php

There is however one downside: your scheduled script would also be invokable from the outside. This is something you should manage. (Either through .htaccess Allow/Deny directives, or some form of generating and providing one-time tokens from CRON).

(One last sidenote: make sure you use the DNS name of your server, if you use localhost, the address is probably going to be 127.0.01, which is not very helpful) ;)

jhkuperus
  • 1,439
  • 11
  • 15