【发布时间】:2016-12-13 12:20:26
【问题描述】:
我想将输入字段内的文本发送到 URL 并触发 $GET 函数。
<form action="" method="get">
URL:<input type="text" name="url" size="100px" placeholder="URL"/>
<select name="url">
<option value="<?php filter_var($_GET['url'],FILTER_VALIDATE_URL); ?>">testdomain1.de</option>
<option value="test2">testdomain2</option>
<option value="test3">testdomain</option>
</select>
<input type="submit" value="Send"/>
</form>
它可以工作,但链接格式错误:
我想要这个:
http://127.0.0.1/title/index.php?url=http://www.tech.de/news/google-will-kein-eigenes-auto-mehr-bauen-10092492.html
但我明白了
http://127.0.0.1/title/index.php?url=http%3A%2F%2F127.0.0.1%2Ftitle%2Findex.php%3Furl%3Dhttp%3A%2F%2Fwww.tech.de%2Fnews%2Fgoogle-will-kein-eigenes-auto-mehr-bauen-10092492.html&url=%3Cbr+%2F%3E%0D%0A%3Cb%3ENotice%3C%2Fb%3E%3A++Use+of+undefined+constant+url+-+assumed+%27url%27+in+%3Cb%3EC%3A%5Cxampp%5Chtdocs%5Ctitle%5Cindex.php%3C%2Fb%3E+on+line+%3Cb%3E22%3C%2Fb%3E%3Cbr+%2F%3E%0D%0A
你能帮帮我吗?
好的,我阅读了 cmets,并更改为:
<?php filter_var($_GET['url'],FILTER_VALIDATE_URL); ?>
但是不行,有没有办法把纯文本粘贴到url?
【问题讨论】:
-
您正在转义 URL 上的特殊字符,请查看 php.net/manual/en/filter.filters.validate.php 以获得更好的清理 URL 的方法
-
没有什么要更正的,这是发送查询参数以便在服务器上处理它们的正确方法。你想要的实际上是畸形的。顺便说一句,您有 2 个名为
url的表单字段,因此也会导致意外结果。 -
Action in form 导致 self ,但是它逃逸了,所以它认为它的相对路径,并附加它。
-
他可以将action留空以获得正确的结果,其他一切正常
-
另外,如果你想在php中使用你的url,你需要
$_GET['url']而不是$_GET[url]。注意引号。
标签: php input hyperlink get malformed