简体   繁体   English

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

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

I am looking for a way for a text field and submission button to take me to a new site, fill out a text input field and hit enter. 我正在寻找文本字段和提交按钮的方式将我带到一个新站点,填写文本输入字段并按Enter键。 The page I want to link to is Googles speed test . 我要链接的页面是Googles速度测试 I know I can link to spped test results as well like this: https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false but how can I have a customer fill out a "test my page" field on my site, hit submit, and it create a link to: https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false with their field submission in the "YOURDOMAINHERE" area of the link. 我知道我可以链接到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及其字段提交。 This seems linke not a huge task but i cannot wrap my head around it, php, javascript??? 这似乎不是一个巨大的任务,但我不能包围我的头,PHP,JavaScript? not sure. 不确定。 Any help would be greatly appreciated. 任何帮助将不胜感激。

You can do something similar to this, although if Google catches you according to their TOC they *could* lock or ban your account: 您可以做类似的事情,但如果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;
?>

Be careful directly injecting headers: 小心直接注入标题:

<?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;
?>

make a submit.php 提交一个submit.php

have the form submit to that script with the "DOMAIN NAME" 使用“DOMAIN NAME”将表单提交给该脚本

your php should look something like this.. 你的PHP应该看起来像这样..

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

That script should work havn't tested it but it'll give you an idea... 该脚本应该工作没有测试它但它会给你一个想法......

make sure you sanitize your inputs too... :) good luck 确保你消毒你的输入...... :)祝你好运

Hows about a simple str_replace ? 关于简单的str_replace怎么样? Something like: 就像是:

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

I haven't tested this at all, but should be something pretty similar 我根本没有测试过,但应该是非常相似的东西

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

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