我正在寻找文本字段和提交按钮的方法,将我带到新网站,填写文本输入字段并按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?不确定。任何帮助将不胜感激。
答案 0 :(得分: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;
?>
答案 1 :(得分:0)
制作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');
该脚本应该可以运行但没有测试过,但它会给你一个想法......
确保你也清理你的输入...... :)祝你好运
答案 2 :(得分: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>
我根本没有测试过,但应该是非常相似的