这是在url中使用空格的好方法吗? [英] is it a good way to use spaces in url?

查看:101
本文介绍了这是在url中使用空格的好方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发电影网站.电影的数据是根据电影名称从数据库中检索的.当某些用户单击电影名称链接时,将生成类似"php?moviename = Live Free Die Hard"的网址,并显示与该电影相关的完整信息.我的问题是,我要在电影名称之间使用空格,如果我想根据电影名称获取电影详细信息,则必须在该名称之间使用空格,但这是一种安全的好方法吗?如果不是,我还应该使用其他方式吗?

I am developing a movies website. The data of the movie is retrieved from the database on the base of movie name. When Some user click on the movie name link a url of like this "php?moviename=Live Free Die Hard" is generated and the full information related to that movie is shown. My question is that I am using spaces between the name of the movie which is compulsory if I want to get the movie details on the basis of movie name, But is it a good and secure way? if not, what else way should i use?

推荐答案

查看以下URL:

http://en.lmgtfy.com/?q=%22Live+Free+Die+ Hard%22 [ ^ ].

这是逃脱空格的方法.在此示例中,它将搜索字符串传递到-只需单击它,您将看到.我在这里看不到任何问题.是的,这是一种安全的方法.

—SA
Look at this URL:

http://en.lmgtfy.com/?q=%22Live+Free+Die+Hard%22[^].

This is the way to escape the blank spaces. In this example it passes the search string to— just click it and you will see. I don''t see any problem here. Yes, this is a secure way.

—SA


通常,URL中的空格是一件坏事:在完全构造URL之前,应先进行HTML编码和解码.看一下Google等所做的事情:&"号被转换为%26",哈希被转换为%23",依此类推.用户可能输入的字符范围可能很大,或者可能出现在电影名称中的字符范围可能会弄乱事情.更好地对它们进行编码并防止出现问题.
Normally, spaces in a URL are a Bad Thing: you should do HTML encoding and decoding before you construct the URL completely. Look at what Google and so forth do: an ampersand is translated to "%26", a hash to "%23" and so forth. There are a range of characters your user could type or which could appear in a movie name which could potentially mess things up. Better to encode them and prevent problems.


这篇关于这是在url中使用空格的好方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆