首页 > 解决方案 > 我如何使 php 代码到达 url 和路径

问题描述

我正在尝试制作一个 php|html 代码,它将执行以下操作首先,当我们提交我们的网址时我有一个输入当我们提交一个像“example.com”这样的网址时,我将有一个包含一些路径名的数组

name1.php
name2.php

如果该文件存在于该域中,则输出将为真(如果不是假的话)。我真的在为连接部分苦苦挣扎,我不知道如何连接到路径,如果存在的话,那么响应是正确的。我到处搜索,但没有找到与此相关的任何内容。谢谢!

标签: phphtmlfunctionurlpath

解决方案


我得到了你需要的基本知识。

首先,我提供代码,然后提供有用的链接。

<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 的更多信息

工作演示

希望这可以帮助


推荐阅读