0

我有一个视频网站,我需要创建一个链接或按钮,以便访问者可以单击报告损坏的链接。

我试图包括REQUEST_URI但到目前为止没有成功。URL 永远不会显示。这是report.php的内容:

<?php
$to = 'admin@domain';
$subject = 'domain.com Broken Link';
$message = '
<html>
<head>
  <title>Dead Link from domain.com</title>
</head>
<body>
  <p>The website contains a DEAD LINK</p>
  <p>Please fix or remove the faulty file or page.</p>
<?php 
function url_origin( $s, $use_forwarded_host = false )
{
    $ssl      = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
    $sp       = strtolower( $s['SERVER_PROTOCOL'] );
    $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
    $port     = $s['SERVER_PORT'];
    $port     = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
    $host     = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
    $host     = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
    return $protocol . '://' . $host;
}

function full_url( $s, $use_forwarded_host = false )
{
    return url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
}

$absolute_url = full_url( $_SERVER );
echo $absolute_url;
?>
</body>
</html>';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
mail($to, $subject, $message, implode("\r\n", $headers));
echo ("The report has been sent.<br>Thank you for your time.");
?>
4

1 回答 1

3

你这样做是错的。假设您目前在其中,http://example.com/some-page并且您想将此页面报告为断开的链接。然后在您的页面中放置一个报告按钮,如下所示:

<a href="report.php?url=<?= urlencode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>">Report</a>

报告.php:

<?php

if (isset($_GET['url']) && filter_var($_GET['url'], FILTER_VALIDATE_URL)) {

    $to = 'admin@example.com';
    $subject = 'example.com Broken Link';
    $message = 'The website contains a DEAD LINK.<br>Please fix or remove the faulty file or page: ' . urldecode($_GET['url']);
    $headers = ['MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1'];

    mail($to, $subject, $message, implode("\r\n", $headers));
    echo 'The report has been sent.<br>Thank you for your time.';

}
于 2019-12-10T15:30:03.720 回答