简体   繁体   English

验证URL中的变量

[英]Validate vars in URL

If I know what vars I can have in my URL how do I validate my URL and ignore the ones that aren't on my list? 如果我知道我的URL中可以包含哪些变量,该如何验证我的URL并忽略那些不在列表中的变量?

I suppose I will have all 'good' vars in an array 我想我将在数组中拥有所有“好”变量

$good = array("name", "car", "year", "color");

Then I need to get the request URL, then break it apart looking for QUERY elements and loop those against my $good array, strip the ones that don't belong and process request. 然后,我需要获取请求URL,然后将其拆开以查找QUERY元素,并将其循环到我的$ good数组中,剥离不属于的元素并处理请求。 Seems like a good plan in theory. 理论上似乎是一个好的计划。 Or is there a better plan? 还是有更好的计划? If it's OK, how do I do all that? 如果可以,我该怎么做?

$url = http://mydomain.com/?car=1&color=red&bad=asdasd

尝试使用此命令: http_build_query

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM