0

我正在寻找一种方法让文本字段和提交按钮将我带到一个新站点,填写文本输入字段并按 Enter。我要链接的页面是Googles speed test。我知道我也可以像这样链接到 spped 测试结果: https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false 但是我怎样才能让客户在我的网站上填写“测试我的页面”字段,点击提交,然后它会创建一个链接: https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2FYOURDOMAINHERE&mobile=false 在他们的字段提交中链接的“YOURDOMAINHERE”区域。这似乎链接不是一项艰巨的任务,但我无法绕过它,php,javascript?没有把握。任何帮助将不胜感激。

4

3 回答 3

2

你可以做类似的事情,虽然如果谷歌根据他们的 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;
?>
于 2013-04-09T17:18:16.030 回答
0

做一个 submit.php

使用“域名”将表单提交到该脚本

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

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

该脚本应该可以工作并没有对其进行测试,但它会给你一个想法......

确保你也清理你的输入...... :) 祝你好运

于 2013-04-09T16:40:21.770 回答
0

简单的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>

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

于 2013-04-09T16:42:50.197 回答