php - 我如何使 php 代码到达 url 和路径
问题描述
我正在尝试制作一个 php|html 代码,它将执行以下操作首先,当我们提交我们的网址时我有一个输入当我们提交一个像“example.com”这样的网址时,我将有一个包含一些路径名的数组
name1.php
name2.php
如果该文件存在于该域中,则输出将为真(如果不是假的话)。我真的在为连接部分苦苦挣扎,我不知道如何连接到路径,如果存在的话,那么响应是正确的。我到处搜索,但没有找到与此相关的任何内容。谢谢!
解决方案
我得到了你需要的基本知识。
首先,我提供代码,然后提供有用的链接。
<html>
<form method="post">
<input type="url" name="url" /><br>
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$file = $_POST['url']; //The link submitted
$file_headers = @get_headers($file); //We retrieve the headers of the link
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
//If the header above(which indicates the page doesn't exist) returns true we will show this
$exists = "The page Does not Exist";
}
else {
//If returns true we gonna show this
$exists = "The Page Exists";
}
echo $exists;
}
?>
</html>
我认为这是您需要的基本内容。您告诉过您要搜索存储在数组中的一些文件。您可以使用此代码轻松地做到这一点,方法是将页面名称放在链接之后,如下所示:
$file = $_POST['url'];
$finalurl = $_POST['url']."name1.php";
在此处了解有关 PHP 中 get_headers 的更多信息
希望这可以帮助
推荐阅读
- r - 如何在plotly中使用layout()函数来设置轴标题R
- smalltalk - whileTrue 在闭包 Smalltalk 中?
- reactjs - onClick 第二次没有路由到正确的页面
- docker - Canonical LXD 容器软件和 docker 容器软件之间的主要区别是什么?
- java - java模块化和cxf-xjc-plugin从xsd文件生成包
- javascript - 如何使用 SVG(而不是 JSON 数据)创建 D3 地理投影
- sql - 按限制使用的顺序和偏移量未按预期顺序返回结果
- telegram - 如何将我收到的电报信息发送到电子邮件
- python - 在没有硬编码位置的情况下从 python 运行 perl
- sql - 如何按总和小于 x 对数据进行分组