简体   繁体   中英

Can I use header() to pass query string parameters?

I'm using XAMPP on Windows.

I've congigured Apache to redirect all requests to a controller.php file. The controller logs all requests to the database before any other processing takes place and it does a few other things too including checking permission to access the files involved.

Most requests map to a file which I then serve with appropriate headers and a readfile. For example:

header ( 'Content-Type: text/css' );
header ( 'Content-Length: ' . filesize ( $file ) );
readfile ( $file );

My problem is that if the URL contains a query string I don't know how to pass that to the file.

http:///myswf.swf?q1=test maps to C:\\SWF\\myswf.swf

header ( 'Content-Type: applicaton/x-shockwave-flash' );
header ( 'Content-Length: ' . filesize ( $file ) );
readfile ( $file );

fails to pass the q1 parameter to the SWF.

I can't tinker with the SWF.

How should I call the SWF and successfully pass the parameters from within PHP?

The SWF file is not executed on the server. As such, you cannot "pass" anything to the SWF file. The file is simply downloaded by the client and then run in the browser, which is were it will get the URL parameters. From the client side, this looks like this (simplified):

As long as the process works like this on the client side, it doesn't matter how exactly you serve the file.

As far as i understand it, you cannot use GET parameters in a filename, so readfile(filename.php?q=123); will NOT pass parameters,

In fact i think the only way you could do this is with a remote file_get_contents(); suchas:

echo file_get_contents("http://domain.com/file.swf?params");

In that case, the webserver at domain.com will handle the parameters to the swf file, this means though that the SWF file will need to be publically accessible, but no-one will figure where it is located, so you could have a folder like domain.com/asfqwasc213412sad/file.swf to obscure it

Im not too experienced on how SWF handles GET params, so this is all assumption in terms of serving the SWF file with the params

Update Thank you @deceze for this info, this probably won't work on SWF files because of the way the params work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM