Board logo

標題: file_get_contents($url)問題 [打印本頁]

作者: jwschow    時間: 2021-10-29 16:56     標題: file_get_contents($url)問題

有關file_get_contents($url)問題


$url="https://somewhere.com/dir/";
$url = $url . "abc";
echo file_get_contents($url);


在somewhere.com/dir/, 如何寫一段code, return返"abc" (或任何string) ?
作者: freefdhk    時間: 2021-10-30 13:55

你係入面整個 index.php 內容係  phpinfo();   你去睇下邊個數值係記錄左條 path string
你就用佢cut 返 自己條 path 就會係你想要既野.
再 echo 返出去.
作者: javacomhk    時間: 2021-10-30 14:25

You have to add options or better to use curl instead
See reference here

https://stackoverflow.com/questi ... f-file-get-contents
作者: KinChungE    時間: 2021-10-30 20:40

你會唔會考慮用$url = $url . "?abc"?
如果用佢就$_GET已經搵到
否則要用.htaccess整rewrite rule
作者: jwschow    時間: 2021-10-31 10:59

回覆 1# jwschow

我自問自答:

做.htaccess

DirectorySlash Off
Options FollowSymLinks Indexes
DirectoryIndex index.php

RewriteEngine on

RewriteCond %{REQUEST_FILENAME}  -d
RewriteRule  ^.*$  -  [L]

RewriteCond %{REQUEST_FILENAME}  -f
RewriteRule  ^.*$  -  [L]

RewriteRule ^.*$    index.php [L]


再係index.php:

$last = explode("/", $_SERVER['REQUEST_URI'], 3);
echo $last[2];


要用rewrite, 否則任何string都食唔入去index.php, 只會話冇呢頁.





歡迎光臨 電腦領域 HKEPC Hardware (https://www.hkepc.com/forum/) Powered by Discuz! 7.2