Archadian Posted March 4, 2007 Share Posted March 4, 2007 Does anyone know why $_SERVER['SERVER_ADDR'] isn't returning anthing? and which global array i should use to return "localhost" and 127.0.0.1 (localhost default IP) Thanks I use Windows 2003 Server IIS 6.0 Link to comment https://forums.phpfreaks.com/topic/41134-_server/ Share on other sites More sharing options...
Archadian Posted March 4, 2007 Author Share Posted March 4, 2007 bump - Anyone know. The reason i ask is because i don't want a script to be able to be seen by going directly to it through URL. I want to make the script to output Hacking Attempt when someone tries to view it with IE, etc. but make it where only the server can read it. Thanks Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199243 Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 Run this to list the available values <?php echo '<pre>', print_r($_SERVER, true), '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199246 Share on other sites More sharing options...
Archadian Posted March 4, 2007 Author Share Posted March 4, 2007 thx, $_SERVER['SERVER_ADDR'] isn't available, how do i make it available? Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199254 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 1) Why do you need a variable that holds "localhost". Can't you use it directly? Same question goes for 127.0.0.1. 2) From one of the comments I found in the manual: To get the server address, you can use $_SERVER['SERVER_ADDR']. However, this only works when your PHP process is running on a webserver, not when running PHP as CLI. Here is a function which will also return the server address when running on linux (eth0 is hardcoded as the network interface, modify if necessary). <?php function getServerAddress() { if($_SERVER['SERVER_ADDR']) { return $_SERVER['SERVER_ADDR']; } $ifconfig = shell_exec('/sbin/ifconfig eth0'); preg_match('/addr:([\d\.]+)/',$ifconfig,$match); return $match[1]; } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199308 Share on other sites More sharing options...
Archadian Posted March 4, 2007 Author Share Posted March 4, 2007 im running WIndows 2003 Server IIS 6.0 on my server Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199330 Share on other sites More sharing options...
Archadian Posted March 4, 2007 Author Share Posted March 4, 2007 bump - How do i make $_SERVER['SERVER_ADDR'] available? or does anyone know how i can secure the script so that only include() and the server can read it and anything else it gives a die() error Thanks Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199360 Share on other sites More sharing options...
Archadian Posted March 4, 2007 Author Share Posted March 4, 2007 bump - Anyone? Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199403 Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 I'm running XP, IIS 5 and $_SERVER['SERVER_ADDR'] is available. If you are calling the page via your IIS server it should be there. If I use the IIS control panel then on the Directory Security tab there is a section titled "IP and Domain name restrictions" but it is greyed-out/locked on mine. Check yours. You may be able to affect it from there. Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199409 Share on other sites More sharing options...
Archadian Posted March 4, 2007 Author Share Posted March 4, 2007 Mine isn't locked out but i have no clue how to make SERVER_ADDR available :/ Link to comment https://forums.phpfreaks.com/topic/41134-_server/#findComment-199437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.