【问题标题】:Running .htaccess from php + $_GET friendly urls + cURL issue从 php + $_GET 友好 url + cURL 问题运行 .htaccess
【发布时间】:2019-03-22 15:53:53
【问题描述】:
我需要问你如何从PHP运行.htaccess,因为我正在制作软件,但我希望用户可以通过语言设置自己的链接名称,但我只能在.htaccess中这样做,但是在.htaccess 我不知道如何从 PHP 语言中获取,然后使用它来指定哪些补丁将存在。我还想在 PHP 中创建友好的 URL(从 .php?id=0 到 .php/id/0)。
最后... cURL。
我看到在一个软件中,我如何使用 cURL 读取页面文本(我有链接 my.ip.com/idk.php?id=3 并且来自服务器的 id 3 只会说文本“ok”,我想将该文本获取到 PHP 并使用它)
【问题讨论】:
标签:
php
.htaccess
curl
get
placeholder
【解决方案1】:
1) 你不能用任何东西运行 .htaccess。这是您的网络服务器的配置文件。
2)http://you.com/@username的例子
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^@(.+)$ profile.php?username=$1 [L,QSA]
然后在profile.php中获取$_GET["username"]
3) 你应该自己制作 .htaccess RewriteRule
4) 关于 cURL 的小例子。
<?php
$post = [
'PostName' => 'PostValue'
];
$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>