Use PHP (with redirect) between JWPlayer and media file

JWPlayer, Apache, PHP

I wanted to use the JWPlayer for playing .FLV (Flash video) media files, but I wanted to use some custom PHP code for cross-server tracking, access control, etc. The JWPlayer code "file" flashvar was directed to the PHP file with an address like /mycode/showvid.php?vid=1988, and in the PHP code I was using something like header ("Location: " . $flvurl) to redirect to the actual media file. I ran into various problems as I tried to get this to work, including the player not appearing at all, the player appearing but never completing its loading, the player seeming to load but the Play button didn't work, and the "Loaded file is not a valid media provider" error appearing in the player.

The Fix: 

There are multiple things that need to be correct:

  1. The ? and = characters in the PHP address (as specified in the "file" flashvar) need to be URL-encoded (use %3F and %3D, respectively); however, the / characters in the address do not need to be encoded (although if & characters are used, they would need to be encoded, using %26)
  2. The "type" flashvar needs to be "video" (and not "flv" as I had read at one point)
  3. The "provider" flashvar needs to be "video" (this is due to the "file" URL not ending in a recognized extension)