Can a URL query string contain a period?

1014 views php
-4

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.

answered question

The PHP URL encode function doesn't touch them so I think it should be there. How are you trying to read it? Per PHP Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs php.net/manual/en/function.urlencode.php Maybe you have rewriting in place and aren't passing over the original value?

please define not working?

The result is empty

1) run your code with the fileName param not containing a . and seeing if the code runs as expected (for instance with a string output shows the if statement worked).

2) var_dump the $_REQUEST['fileName'] value to check it is what you expect (for instance Request var reading may be turned off in PHP.ini).

I don't know what "having rewriting in place" means

You probably don't have it in that case. Output your request and see what it is.

1 Answer

3

Its an url encoded string. You'll need to get the Query via the variable "$_GET".

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

posted this

Have an answer?

JD

Please login first before posting an answer.