09
Aug
06

$_SERVER[REQUEST_URI] doesn’t always work correctly! Here’s how to fix it.

Here’s something important for WP plugin developers that I have discovered on my server with wordpress and many plugins.

While PHP programmers have been taught to use
$_SERVER[REQUEST_URI]
to fetch the current page URI, IT DOESN’T WORK CORRECTLY in all cases with wordpress’s rewrite functions.

I discovered this while working with the paged-comments plugin. It caused the template and other plugins to not see the proper URI and miss out on the extra stub in the URL.

After some studying of phpinfo results, I discovered that the proper, complete URI was shown in:
$GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"];

So I highly recommend that plugin developers use that reference instead.
Yes, I know they should be identical but apparently it’s an Apache + PHP bug.

My server has apache 1.33 and php 4.2 so your milage may vary on the bug.
But since ALOT of people have that server combo, trust me, this prevents problems.


2 Responses to “$_SERVER[REQUEST_URI] doesn’t always work correctly! Here’s how to fix it.”


  1. 1 Rodrigo
    February 12, 2008 at 11:03 pm

    I had a similar problem. My php file inserted the $_SERVER['REQUEST_URI'] bit in a form sending stuff using the post method, and sent it as a hidden field to the logout script.

    The logout script would get it and then re-direct to an index page using the header() function. However, this redirection only worked with Mac’s Safari for some weird reason. Anyway, the solution for me was to break out of PHP and use html’s tag. This way it all worked!. It’s strange how this works on some browsers and on others it doesn’t since it seems to be a server side issue not a client-side issue. Anyway, I’m happy I fixed it!

  2. July 26, 2009 at 2:10 pm

    Hi,
    Do you how to get this technique working on bbpress?

    The problem is tracking conversions, as the “register” button is on every page, conversions cant be measured accurately if users register to the website, clicking on the button from a different page.

    If I have domain/
    And the register button is on the index domain/register.php
    Measuring conversions that went from the index would go fine.

    Suppose if a user is on page:
    Domain/topic.php?id=694

    I’d really love this to change into: domain/register.php?topic.php?id=694 (or something similar, but the entrance path should be also in the url)

    Any ideas?

    Thanks.


Leave a Reply




c

Blog Stats

  • 63,755 hits

 

August 2006
S M T W T F S
    Feb »
 12345
6789101112
13141516171819
20212223242526
2728293031