Obtaining PHP Remote Address Info from URL

空扰寡人 提交于 2019-12-13 07:29:42

问题


I am new to PHP and keen to learn and I was wondering if people could please let me know how to obtain phpinfo information, specifically under the Apache Environment, the variable REMOTE_ADDR?

I basically provide a user with a url to a partcular website, which ultimately returns them a csv file where they can either save/delete or cancel.

On the same URL, I was wondering if I can call a PHP function to obtain this information or even better, call the variable directly from the URL?

Any assistance would be appreciated.

Thanks.


回答1:


You can obtain REMOTE_ADDR from the $_SERVER global array

$_SERVER["REMOTE_ADDR"];

As for the URL, you can use $_GET to pass data through a URL.




回答2:


As far as I could understand it, you can get it like this:

$addr = $_SERVER['REMOTE_ADDR'];
echo $addr;

And if you want to give this info to anyone, you can put it in URL like this:

<a href="whateverpage.php?addr=<?php echo $addr;?>">Link</a>

Now the address will be there into the URL (query string).




回答3:


Use getenv('REMOTE_ADDR') or $_SERVER['REMOTE_ADDR'] can get the variable you want.

The fopen() can be used for open a file in a remote host, for example:

$handle = fopen("http://www.example.com/data.csv", "r");

so you can open a csv file in the remote server via http protocol.



来源:https://stackoverflow.com/questions/2235083/obtaining-php-remote-address-info-from-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!