OpenCraft
Follow OC!
  • Home
  • About
  • Solutions
  • Portfolio
  • Clients
  • Blog
  • Contact

Beware PHP $_REQUEST!

Wed, 2008-10-08 01:37
Tags:
  • coding
  • drupal
  • php
By: 
Karim Ratib

I recently came across an interesting bug that I thought to share with you PHP/Drupal heads.

Some Drupal modules use the query part of a URL (arguments after the question mark "?") to send information. In my case, the D6 Batch API uses arguments "op" and "id" to specify which batch operation should be executed. At one point, my module was creating a new batch operation with id=68. However, the batch operation kept failing with Drupal saying "Access denied". After finding the line where the code failed, I inserted var_dump($_REQUEST) and found that id had always value = 1, no matter what value I sent on the URL query! However, var_dump($_GET) reported id=68. How weird is that!

Well, the problem turned out to be that $_REQUEST is an array obtained by merging $_POST, $_GET and cookies. Some other PHP application had created a root cookie named "id", and $_REQUEST was picking up that value instead of the one in the URL. When I removed that cookie from my browser, the code worked correctly.

The lesson? Fix your "request_order" php.ini directive (or "variables_order" pre-PHP 5.3) to something that makes sense to your code. In general, watch for name collisions between $_GET, $_POST and cookie values.

  • kratib's blog

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Our work

De Birs Yachts

In a simple professional looking design, Debirs Yachts website is...

Sanabel
Sanabel

Sanabel requested a bilingual dynamic web portal to improve its...

View our complete portfolio

Related posts

  • Drupal performance optimization part 1
  • The Automatic Resource Destructor pattern
  • Run webinject (nagios plugin) for drupal projects
  • Coloring 1pixelout flash player in audio module
  • Apache MultiViews automatically appends file extensions

More posts by this author

  • Reverse-translating a string back into English in Drupal
  • Who needs Google Spreadsheets: Use Sheetnode!
  • Code contribution: Views Bulk Operations (VBO)
  • The Automatic Resource Destructor pattern
  • Where in the world is open source?

OpenCraft

  • About
  • Team
  • Process
  • Community
  • Media Kit
  • Portfolio
  • Clients
  • Industries
    • Social economic development
    • Multimedia culture
  • Services
    • Drupal development
    • Information architecture
    • Open source software development
    • Social network engineering
  • Request quote
  • Contact
  • Search
Blog

Our profiles at:

Drupal Google
rss

Creative Commons License
search