繁体   English   中英

自动填写表单,其中包含指向外部页面的链接

[英]Auto-fill form with link to external page

我正在寻找文本字段和提交按钮的方式将我带到一个新站点,填写文本输入字段并按Enter键。 我要链接的页面是Googles速度测试 我知道我可以链接到spped测试结果,如下所示: https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=falsehttps://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false但是如何让客户填写“测试我的页面”我的网站上的字段,点击提交,并在链接的“YOURDOMAINHERE”区域中创建一个链接: https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=falsehttps://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false及其字段提交。 这似乎不是一个巨大的任务,但我不能包围我的头,PHP,JavaScript? 不确定。 任何帮助将不胜感激。

您可以做类似的事情,但如果Google根据他们的TOC抓住您,他们*可以*锁定或禁止您的帐户:

<?php
if (!empty($_POST['url'])){
    $url = preg_replace('!http[s]://!','',strip_tags($_POST['url']));
    $url = preg_replace('![%]!','_',urlencode($url));
    $newlink = "https://developers.google.com/speed/pagespeed/insights#url=$url&mobile=false";

    $page = '<!doctype html>
<html lang="en">
<head>';

    $page .= '<script type="text/javascript">
    function replaceDoc()
  {
  window.location.replace("'.$newlink.'")
  }
    </script>';


$page .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page for testing</title>
</head>
<body onload="replaceDoc()">

    <a href="'.$newlink.'">Test your page.</a>

</body>
</html>
    ';
} else {
 $page = '<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page Checker</title>
</head>
<body>
<form method="post">
Enter your URL:<br />
<input name="url" type="text" style="width:50em;" />
<input type="submit" name="submit" value="Check your page" />
</form>
</body>
</html>';

}

echo $page;
?>

小心直接注入标题:

<?php
if (!empty($_POST['url'])){
    $url = preg_replace('!http[s]://!','',strip_tags($_POST['url']));
    $url = preg_replace('![%]!','_',urlencode($url));
    $newlink = "https://developers.google.com/speed/pagespeed/insights#url=$url&mobile=false";

    header("Content-Type: application/x-www-form-urlencoded");
    header("Referer: https://developers.google.com/speed/pagespeed/insights");
    header("Location: $newlink");

} else {
 $page = '<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page Checker</title>
</head>
<body>
<form method="post">
Enter your URL:<br />
<input name="url" type="text" style="width:50em;" />
<input type="submit" name="submit" value="Check your page" />
</form>
</body>
</html>';

}

echo $page;
?>

提交一个submit.php

使用“DOMAIN NAME”将表单提交给该脚本

你的PHP应该看起来像这样..

$domainName = $_POST["domainname"];
$redirectURL = "https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2F".$domainName."&mobile=false";
header('Location: $redirectURL');

该脚本应该工作没有测试它但它会给你一个想法......

确保你消毒你的输入...... :)祝你好运

关于简单的str_replace怎么样? 就像是:

<?php

$link = "https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false";
$replace = "YOURDOMAINHERE";

if(isset($_POST['myDomain'])){
  $newHeader = str_replace($replace, $_POST['myDomain'], $link);
  header("Location: ".$newHeader);
}

?>


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">       
   <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>googleDomain</title>
    </head>
    <body>
        <form action="domain.php" method="post">
            <input type="text" name="myDomain" />
            <input type="submit" />
        </form>
    </body>
</html>

我根本没有测试过,但应该是非常相似的东西

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM