【问题标题】:php input send to URL, malformedphp 输入发送到 URL,格式错误
【发布时间】: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


【解决方案1】:

有将纯文本获取到 url 的方法,但它不安全,因为您不能使用像 filter_varhtmlspecialchars 这样的消毒。

另外,$_GET['url'] 在提交表单之前没有设置,所以第一次发送会导致错误。

这里的选项是在keyup 的表单中包含javascript 来设置action,然后,当您按下提交时,您将被重定向到此网址。如果这不是您想要的,请告诉我们您的脚本需要做什么才能得到正确的答案。

【讨论】:

    猜你喜欢
    • 2015-09-23
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多