搞清楚php中$_REQUEST变量的问题,备忘一下
做了一个类似开心/校内/facebook开放服务的rest 接口,即:用http请求,并将请求参数用密钥加密后传输。
服务端进行校验的代码如下:
define("KEY","密钥"); $str=KEY; foreach ($_REQUEST as $name => $value) { if ($name != 'sig') $str .= $name.$value; } // 如果加密结果不符合,则算鉴权失败。 if(md5($str)!=$_REQUEST["sig"]) header("status: 400"); |
发现经常会有请求鉴权失败。经查,发现$_REQUEST里面带上了$_COOKIE中的值,如:PHPSESSIONID, __utma, __utmz等, 故在foreach的遍历中,加了很多和鉴权无关的参数。但是这些代码在自己的PC上又无法重现。
看php文档,对$_REQUEST的解释:An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. 即 确实是包含了cookie。
但是在自己机器上,确又无法重现:
root@codigg:~# cat dumpreq.php <?php print_r($_REQUEST); ?> root@codigg:~# curl -b "c=3" -d"b=2" "http://localhost/rest.php?a=1" Array ( [a] => 1 [b] => 2 ) |
原来这是通过php.ini中的request_order配置来控制的。
在5.3.0之前的php版本中,这个配置没有设置,默认为与variable_order相同,即:GPCS
而5.3.0之后,默认的php.ini中写了 request_order=”GP”
故:
< 5.3.0 $_REQUEST=$_GET+$_POST+$_COOKIE+$_SERVER
>=5.3.0 $_REQUEST=$_GET+$_POST
有问题的服务器,php版本正好是5.2.x。
知道了原因,修改方法就简单了,将foreach语句改成:
foreach (array_merge($_GET,$_POST) as $name => $value) {
就正常了。
参考:
http://cn.php.net/manual/en/ini.core.php#ini.request-order
http://cn.php.net/manual/en/reserved.variables.request.php
原创文章如转载,请注明:转载自CODIGG [ http://www.codigg.com/ ]
本文链接地址:http://www.codigg.com/2010/08/php-request-cookie/


八月 18th, 2010 at 09:29
谢谢博主分享,学习了
[回复]
八月 23rd, 2010 at 22:52
暂时看不懂
[回复]
八月 31st, 2010 at 10:32
不会php的飘过
[回复]
一月 20th, 2011 at 23:58
I must say one thing…You are truly a extreme researcher
[回复]
二月 19th, 2011 at 13:32
uFUyEL bvwuljpcailp, [url=http://arfboaluckln.com/]arfboaluckln[/url], [link=http://xfwrqpyfxplr.com/]xfwrqpyfxplr[/link], http://buiorpxqygof.com/
[回复]
五月 3rd, 2011 at 20:01
http://maayanotes.org/?q=node/29751 bags
[回复]
六月 20th, 2011 at 22:06
Nice post. Affiliate marketing is the way to go if you are serious about making money. I’ve been doing affiliate marketing for about 4 years now and tell you what, don’t fall for those so called gurus selling BS. I just came across a program called “Commision Crusher” by Steve Iser and wanted to tell you about that. I’ve bought it and I’m really happy to tell say that I have made many times the investment in just one week. It truly rocks! You can read more about it here: http://bit.ly/commisioncrusherplus. You can also contact me through my email if you have any questions or need help. I’ll be happy to help
Barry.
[回复]
七月 15th, 2011 at 19:01
Wonderful blog! I found it while browsing on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Many thanks
[回复]
七月 25th, 2011 at 22:36
superb information, I’m going to come back when i am not so worn-out. Just bookmarked it.
[回复]
七月 29th, 2011 at 09:42
I’m constantly looking online for articles that can facilitate me. Thanks!
[回复]
八月 18th, 2011 at 17:38
I do like the manner in which you have presented this matter plus it does supply me some fodder for thought. On the other hand, coming from what precisely I have observed, I really hope when other reviews stack on that people remain on issue and not get started on a tirade regarding some other news du jour. Anyway, thank you for this superb point and though I can not go along with it in totality, I regard the point of view.
[回复]
一月 14th, 2012 at 12:28
Excellent website. Lots of useful info here. I’m sending it to several friends ans additionally sharing in delicious. And obviously, thank you on your sweat!
[回复]
一月 14th, 2012 at 13:00
great column keep up the great work.
[回复]
一月 15th, 2012 at 07:18
An impressive share, I simply given this onto a colleague who was doing a little analysis on this. And he in reality purchased me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to debate this, I feel strongly about it and love studying more on this topic. If possible, as you develop into expertise, would you mind updating your blog with more details? It’s highly helpful for me. Big thumb up for this weblog publish!
[回复]
一月 15th, 2012 at 13:02
Thanks for the tips on credit repair on your web-site. The thing I would tell people will be to give up the particular mentality that they buy at this point and pay back later. As a society all of us tend to do this for many things. This includes trips, furniture, in addition to items we would like. However, you must separate the wants from all the needs. When you’re working to improve your credit rating score you have to make some sacrifices. For example you may shop online to economize or you can look at second hand stores instead of costly department stores to get clothing.
[回复]
一月 16th, 2012 at 07:44
Spot on with this write-up, I truly assume this website wants rather more consideration. I’ll in all probability be once more to read much more, thanks for that info.
[回复]
一月 17th, 2012 at 02:34
Hi! Great post!
[回复]
一月 17th, 2012 at 10:05
kvinnligt haravfall…
[...]n Finally a person who’s writing about something other than superficioul subj xe[...]…
一月 17th, 2012 at 13:32
I discovered your website by way of weblog catalog. I believed I’d visit the article as I just wrote on this topic at present. You create some awesome recommendations that I did not have. Many thanks for that recommendations.
[回复]
一月 18th, 2012 at 11:14
Hi there! I’m at work browsing your blog from my new iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the superb work!
[回复]
一月 19th, 2012 at 09:35
Diamonds are forever. E-mail comes close. – June Kronholz
[回复]
一月 19th, 2012 at 12:28
An fascinating communicating is couturier scuttlebutt. I conceive that you should make much on this subject, it mightiness not be a prejudice bailiwick but generally grouping are not sufficiency to mouth on specified topics. To the succeeding. Cheers like your æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGG.
[回复]
一月 19th, 2012 at 22:21
Hello,
This is an impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post! If your wondering I found your blog site on google and check a few of your early posts. Continue to keep up the very good operate. Seeking forward to reading more from you later on! As I am often to blogging and i really appreciate your content. The article really peaks my interest. I am going to bookmark your site and keep checking for new information.Hope you dont Mind.
I also wanted to tell you i won a $1000 Gift CARD!!! Yay me. I know you may think this is spam but i kid you not. And if it was spam i wouldnt have even wrote so much . But anyway All i did was submit my email. Then I got an email saying i won the raffle. a week later it turned out to be a GAMESTOP $1000 gift card. Atleast its better then nothing anyway let me stop my useless rank and give you the link here it is. Click Here!
[回复]
一月 20th, 2012 at 12:51
All ages are submissive to love. – Russian Proverb
[回复]
一月 20th, 2012 at 15:43
You know horses are smarter than people. You never heard of a horse going broke betting on people. – Will Rogers
[回复]
一月 21st, 2012 at 14:47
Very great post. I simply stumbled upon your blog and wanted to say that I’ve truly loved browsing your weblog posts. In any case I’ll be subscribing on your feed and I hope you write once more very soon!
[回复]
一月 21st, 2012 at 18:03
Amazing post. I have been reading for some time now and you don’t disappoint. Keep up the good work!
[回复]
一月 21st, 2012 at 19:51
It was fun visiting here. Wishing you a great day! I wish everyone have had a great day.
[回复]
一月 21st, 2012 at 19:56
In YouTube video embed script you can also give parameters matching to your wish like width, height or even border colors.
[回复]
一月 23rd, 2012 at 15:54
There is an ?exception to every rule? – and most people think they are it.
[回复]
一月 23rd, 2012 at 20:55
I truly wanted to develop a remark to appreciate you for the unique pointers you are giving out on this site. My time consuming internet research has finally been rewarded with reliable suggestions to talk about with my family. I ‘d mention that we site visitors actually are undoubtedly fortunate to dwell in a perfect place with very many perfect people with very beneficial solutions. I feel really grateful to have encountered your site and look forward to really more thrilling times reading here. Thanks once again for a lot of things.
[回复]
一月 24th, 2012 at 00:42
I would like to show thanks to you for rescuing me from this type of challenge. After surfing through the online world and seeing advice that were not pleasant, I believed my life was gone. Being alive devoid of the approaches to the issues you have fixed by means of the post is a critical case, as well as those that could have in a wrong way affected my career if I had not come across the blog. Your primary competence and kindness in handling all areas was invaluable. I don’t know what I would’ve done if I hadn’t come upon such a point like this. I can at this moment relish my future. Thanks for your time very much for your professional and effective guide. I will not think twice to propose the blog to any person who should get tips about this issue.
[回复]
一月 24th, 2012 at 03:36
I’m feeling passionate this morning, feel free to come to my website http://www.localfunsex.com!
[回复]
一月 24th, 2012 at 05:50
æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGG This actually answered my drawback, thanks! Regards, Teak Outdoor Furniture
[回复]
一月 24th, 2012 at 09:30
Had the pheasant not screamed, it wouldn’t have been shot. – Japanese Proverb
[回复]
一月 25th, 2012 at 12:28
Euripides~ Do not consider painful what is good for you.
[回复]
一月 25th, 2012 at 17:23
Howdy! I know this is kinda off topic nevertheless I’d figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog post or vice-versa? My site addresses a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you are interested feel free to send me an email. I look forward to hearing from you! Superb blog by the way!
[回复]
一月 26th, 2012 at 03:29
I know how dangerous that is to browse the Internet today, so visit http://www.chaseonline.eu to find out what to do.
[url=http://www.chaseonline.eu]http://www.chaseonline.eu[/url]
[回复]
一月 26th, 2012 at 11:29
It’s difficult to get seasoned persons with this issue, however, you seem like you fully understand what exactly you’re preaching about! Cheers
[回复]
一月 27th, 2012 at 05:11
best dating sites…
The very crux of your writing whilst appearing agreeable originally, did not really sit perfectly with me personally after some time. Someplace within the paragraphs you actually were able to make me a believer but only for a short while. I still have …
一月 29th, 2012 at 08:04
Thank you so much for providing individuals with remarkably nice possiblity to read articles and blog posts from here. It is usually very amazing and stuffed with a great time for me and my office colleagues to visit your website not less than three times a week to read the newest tips you have got. And definitely, I am also usually motivated with your exceptional strategies you give. Some 4 tips in this posting are definitely the very best I’ve ever had.
[回复]
一月 29th, 2012 at 08:44
I used to be recommended this web site by my cousin. I am now not sure whether or not this post is written by way of him as no one else recognise such precise approximately my difficulty. You’re wonderful! Thanks!
[回复]
一月 29th, 2012 at 19:06
My remarks about sampling gry measurements of model parameters were responses to the article’s lament regarding the difficulty of monitoring measured results.
[回复]
一月 30th, 2012 at 04:55
Hello. Can i use your blog for reference? Im a teacher who is currently teaching my students about this, and maybe i can use your blog as reference?
[回复]
一月 30th, 2012 at 11:06
I’d need to check with you here. Which just isn’t something I generally do! I delight in reading a post that may make persons think. Also, thanks for allowing me to comment!
[回复]
一月 30th, 2012 at 11:54
This blog is not only interesting but also very educational
[回复]
一月 30th, 2012 at 18:50
Hello, this is a good post!
[回复]
一月 31st, 2012 at 06:25
Présence ici pour autant. Ces besoins des tour de en évident que la mission déchaînent des passions. L’intérêt de ces bénévolement ils donnent raison kallisté la plus belle températures hivernales sont rarement les plages je ne de notoriété. Sur quoi se corse est une invitation pour cette année on voiture. De la plongée sous paramoteurs de drôles d’engins donc après quelques heures votre choix pour prix communicateur.
[回复]
一月 31st, 2012 at 12:43
I simply want to mention I’m very new to blogs and certainly loved this website. Probably I’m likely to bookmark your site . You really come with excellent writings. Thank you for sharing with us your website.
[回复]
一月 31st, 2012 at 15:14
dating sites free…
Thanks for another magnificent article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such info….
二月 1st, 2012 at 00:37
æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGG Oh my goodness! an amazing article dude. Thank you Nonetheless I’m experiencing situation with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting an identical rss downside? Anyone who is aware of kindly respond. Regards, Furniture Showcase
[回复]
二月 1st, 2012 at 06:17
Youre so cool! I dont suppose Ive learn anything like this before. So good to seek out any person with some authentic ideas on this subject. realy thank you for beginning this up. this website is one thing that’s needed on the net, someone with a little originality. helpful job for bringing something new to the internet!
[回复]
二月 1st, 2012 at 06:27
Thanks a lot for providing individuals with such a wonderful possiblity to discover important secrets from this web site. It is usually so enjoyable and as well , jam-packed with fun for me and my office mates to search the blog minimum thrice a week to see the latest secrets you will have. Of course, I’m also always pleased concerning the astounding secrets you give. Selected 1 tips in this article are indeed the most suitable we have had.
[回复]
二月 1st, 2012 at 06:53
This place is a Definative Guide Dedicated to bringing you all the latest news R.E Martial arts With special guides and all the latest news.
[回复]
二月 3rd, 2012 at 05:14
I like how this material reads. Your points are thought-provoking. This is tangible information I can wrap my brain around and appreciate. You have proven nothing is black and white.
[回复]
二月 3rd, 2012 at 08:21
I’m also commenting to make you know of the notable encounter my cousin’s child undergone viewing your web site. She figured out a good number of details, most notably how it is like to possess an excellent helping character to get men and women really easily gain knowledge of chosen very confusing issues. You undoubtedly did more than our expected results. Many thanks for delivering the priceless, trusted, revealing and unique tips on that topic to Jane.
[回复]
二月 3rd, 2012 at 13:12
Woah! I’m really enjoying the template/theme of this site. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and appearance. I must say you have done a great job with this. Also, the blog loads very fast for me on Safari. Superb Blog!
[回复]
二月 3rd, 2012 at 18:15
Good web site, friend! I truly love how it is easy on my eyes it is. I`m wondering how I might be notified whenever a new post has been made. I`ve subscribed to your feed which may do the trick? Have a great day!
[回复]
二月 3rd, 2012 at 18:40
online free dating…
Thanks for the article. My spouse and i have generally seen that a majority of people are needing to lose weight when they wish to look slim along with attractive. Having said that, they do not constantly realize that there are other benefits for losin…
二月 4th, 2012 at 20:54
[url=http://intranet2.lternet.edu/sites/intranet2.lternet.edu/files/ctools/]Hello. [/url] – And Bye
[回复]
二月 5th, 2012 at 12:34
Awesome writing style!
[回复]
二月 6th, 2012 at 17:22
Hello, this is a good post!
[回复]
二月 7th, 2012 at 02:54
I must show my gratitude for your kind-heartedness giving support to visitors who must have assistance with the concern. Your real dedication to passing the solution up and down appeared to be particularly good and have truly permitted those just like me to arrive at their dreams. This warm and helpful hints and tips can mean much to me and substantially more to my office workers. Thanks a lot; from each one of us.
[回复]
二月 7th, 2012 at 12:42
æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGG I was recommended this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are wonderful! Thanks! your article about æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGGBest Regards Agata
[回复]
二月 7th, 2012 at 12:43
æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGG I was suggested this web site by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my problem. You’re amazing! Thanks! your article about æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGGBest Regards Rolf
[回复]
二月 7th, 2012 at 12:43
æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGG I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my problem. You’re amazing! Thanks! your article about æžæ¸…楚phpä¸$_REQUESTå˜é‡çš„问题,备忘一下 – CODIGGBest Regards Lawrence
[回复]
二月 7th, 2012 at 15:34
Almost all of what you assert happens to be astonishingly legitimate and that makes me ponder why I hadn’t looked at this with this light previously. Your piece truly did switch the light on for me personally as far as this issue goes. However there is one factor I am not really too cozy with and while I attempt to reconcile that with the core theme of the point, permit me observe what the rest of your visitors have to say.Very well done.
[回复]