如何从客户端的xml请求中获取服务器信息

发布于 2024-12-20 10:39:44 字数 651 浏览 0 评论 0原文

我可以从哪个网站获取信息来请求读取我的 Web 服务器上的 XML 文件,并将请求中的该信息插入到数据库中吗?

例如,我想开发一个脚本,当客户端在他的服务器上安装我的脚本时,每次他访问他的网站时,他都会调用 simplexml_load_file 来获取信息是否有新版本的脚本以及如何更新它。我想知道谁有我的剧本。


我尝试使用 .htaccess 进行“盲目”操作,但它没有任何作用:(当我调用 text.php 时:

<?php
$myFile = "save.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_SERVER['REMOTE_ADDR']." : ".$_SERVER['REQUEST_TIME']."\n";

fwrite($fh, $stringData);
fclose($fh);

 $xml = file_get_contents('test.xml');
    header("Content-Type:text/xml");  
    echo $xml;
?>

他将我放在 save.txt 文件信息中,该信息来自哪个 IP 地址调用。我可以知道来自哪个网址吗来电了吗? 如何修复调用 XML 文件而不是 php 文件?

Can I get information from which web site is came request to read XML file on my web server, and insert into database this information from request?

For example, I want to develop a some script and when client install my script on his server, every time when he go to his website he call simplexml_load_file to get information if there new version of script and how to update it. I would like to know who has my script.


"blind" I try to make with .htaccess but it didn't work anything :( when I call text.php:

<?php
$myFile = "save.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_SERVER['REMOTE_ADDR']." : ".$_SERVER['REQUEST_TIME']."\n";

fwrite($fh, $stringData);
fclose($fh);

 $xml = file_get_contents('test.xml');
    header("Content-Type:text/xml");  
    echo $xml;
?>

he put me on save.txt file information from which IP address call is coming. Can I know from which web address is call is coming?
And how to fix to call XML file instead php file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作妖 2024-12-27 10:39:44

也许你想尝试使用超级全局 $_SERVER['HTTP_REFERER']。尝试回显它以查看它包含的内容,您就会了解它是如何工作的。在论坛或其他域上放置此脚本的链接,然后单击以查看结果。

要确切地知道谁拥有您的脚本,您可以让他们注册(以便获取他们的名字),或者将域保存在数据库中以便稍后作为日志查看(并且可能手动填写有关该特定域的详细信息)等等。

编辑:

我看到你有一个 XML 文件。好吧,您应该使用 htaccess 并使用不同的脚本处理该请求,并在该脚本中使用 $_SERVER['HTTP_REFERER']。

或者:使其成为将被请求的 php 文件。并执行所有操作来保存您需要的信息,例如引用域,并在文件末尾读取您想要的内容(fread、file_get_contents、文件等)真实的 xml 文件并将其输出...如果如果您遇到问题,请尝试首先使用 header() 设置标头: http://www.php.net/manual/en/function.header.php ,使其看起来(和感觉)像一个真正的 xml 文件。我认为正确的标题应该是 text/xml,或者更好:application/rss+xml。

<?php
    file_put_contents('save.txt', $_SERVER['HTTP_REFERER'].PHP_EOL);
    $xml = file_get_contents('test.xml');
    header('application/rss+xml');
    echo $xml;
?>

将文件另存为 test.php

,然后创建另一个文件 somewhousethescript.html,将其放在同一文件夹中,在其中放入 test.php 的链接(在使用 .htaccess 执行此操作后,您应该直接链接到 test.xml)。

并转到 mrakodol.info/someonewhousethescript.html 并单击链接

并查看 save.txt。在那里您很可能会看到 mrakodol.info/someonewhousethescript.html 这就是我认为您想要的。

如果您确实想保留 .xml 扩展名,则始终可以使用 apache mod-rewrite。如果需要的话我会提供样品。

至于扩展名,然后在该文件夹(看起来是网站的根文件夹)中创建一个新文件并将其命名为 .htaccess,并在其中写入以下行:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^GET$ [NC]
RewriteRule test.xml test.php [NC]

maybe you want to try using super global $_SERVER['HTTP_REFERER']. Try echoing it to see what it contains, and you will get how it works. Put a link to this script on a forum or a different domain and click to see the results.

And to know exactly who have your script, you can make them register (in order to get their name), or save the domains in a database to view later as logs (and maybe fill in manually the details about that specific domain), etc, etc.

EDIT:

I see that you have an XML file. Well you should work with htaccess and handle that request with a different script, and in that script use $_SERVER['HTTP_REFERER'].

OR: make it be a php file that will be requested. And do all the stuff to save what information you need, like the referer domain, and at the end of the file read with what ever you want (fread, file_get_contents, file, etc) the real xml file and output it... if you have problems with it, try setting the header first using header(): http://www.php.net/manual/en/function.header.php , to make it look (and feel) like a true xml file. I thing the correct header would be text/xml, or better: application/rss+xml.

<?php
    file_put_contents('save.txt', $_SERVER['HTTP_REFERER'].PHP_EOL);
    $xml = file_get_contents('test.xml');
    header('application/rss+xml');
    echo $xml;
?>

save the file as test.php

then make another file someonewhousethescript.html, put it in the same folder, put in it a link to test.php (after you do the thing with .htaccess you should link directly to test.xml).

and go to mrakodol.info/someonewhousethescript.html and click the link

and look into save.txt. There you will most probably see mrakodol.info/someonewhousethescript.html this is what I think you wanted.

And if you really want to keep the extension to .xml, you can always use apache mod-rewrite. If it is necessary I will provide a sample.

As for the extension, then make a new file in that folder (the root folder of the website as it seems) and name it .htaccess, and in it write the following lines:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^GET$ [NC]
RewriteRule test.xml test.php [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文