1

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.

Robert Lewis
  • 1,847
  • 2
  • 18
  • 43
  • 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` http://php.net/manual/en/function.urlencode.php Maybe you have rewriting in place and aren't passing over the original value? – user3783243 Nov 07 '18 at 17:52
  • The result is empty – Robert Lewis Nov 07 '18 at 17:56
  • I don't know what "having rewriting in place" means – Robert Lewis Nov 07 '18 at 17:57
  • You probably don't have it in that case. Output your request and see what it is. – user3783243 Nov 07 '18 at 17:59
  • See `access.log`, `var_dump($_SERVER);` and browser inspection for debugging. The mixed case parameter hints foremost at usage errors. And `isset` notice supression should **not** be used until code works as expected. VTC because of the omitted sample code `{ ... }`. – mario Nov 07 '18 at 18:24

1 Answers1

2

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....

Martin
  • 22,212
  • 11
  • 70
  • 132