Robert Lewis
Robert Lewis

Reputation: 1907

Can a URL query string contain a period?

I have URLs like this:

process_request.php?fileName=newpage.html

I attempt to retrieve the fileName parameter with:

if (isset($_REQUEST['fileName'])) { ... }

It's not working and I'm wondering if the period in the file name could be the problem. I can't seem to find a definitive answer. PHP's URL encoding functions don't appear to do anything to periods.

Upvotes: 1

Views: 6271

Answers (1)

Martin
Martin

Reputation: 22760

Fullstops (periods .) are valid query string values.

why? Because:

print urlencode("This is a ... query string! hazzah");

outputs:

This+is+a+...+query+string%21+hazzah

Therefore this is not the cause of your apparent issue.

How to find your actual issue:

  • Re-run your code with the fileName param not containing a . and seeing if the code runs as expected:

    process_request.php?fileName=newpage.html

    if (isset($_REQUEST['fileName'])) { print "it worked!"; die; }
    
  • var_dump() the $_REQUEST['fileName'] value to check it is what you expect (for instance $_REQUEST variables may be turned off in PHP.ini).

    process_request.php?fileName=newpage.html

     var_dump($_REQUEST);
     if (isset($_REQUEST['fileName'])) { print "it worked!"; die; }
    
  • Check your .htaccess (or similar) is not rewriting your actioning URL

  • Check that the if(...) statement IS running and just not giving you the expected result due to another issue, error or failure.

And last but not least....

Upvotes: 2

Related Questions