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) ?

你係入面整個 index.php 內容係  phpinfo();   你去睇下邊個數值係記錄左條 path string
你就用佢cut 返 自己條 path 就會係你想要既野.
再 echo 返出去.

TOP

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

https://stackoverflow.com/questi ... f-file-get-contents

TOP

你會唔會考慮用$url = $url . "?abc"?
如果用佢就$_GET已經搵到
否則要用.htaccess整rewrite rule

TOP

回覆 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, 只會話冇呢頁.

TOP