【问题标题】:How i can make the php code reach an url and an path [closed]我如何使 php 代码到达 url 和路径 [关闭]
【发布时间】:2020-08-03 15:54:07
【问题描述】:

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

name1.php
name2.php

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

【问题讨论】:

  • 诚实吗?我不明白你要做什么。
  • 需要更多细节

标签: php html function url path


【解决方案1】:

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

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

<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 here

Working Demo

希望对你有帮助

【讨论】:

  • 非常感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-30
  • 1970-01-01
  • 1970-01-01
  • 2020-08-25
  • 1970-01-01
  • 2020-01-18
相关资源
最近更新 更多