PHP works on localhost but not dreamhost

software development

#1

Any PHP gurus out there?

I’ve figured out a way around this problem already, but just for the learning opportunity, I wonder if anyone could explain why the following bit of code would work on a local PHP installation (I’m running UniServer 5.6 with no modifications) but when I uploaded it to DreamHost, it wouldn’t work.

I’m using xmoovStream server to pseudo-stream .flv files, and according to the documentation, the following bit of code should check whether a previously generated token is still valid and, if so, start streaming the .flv file. It calls a class to check the validity of the token, isValid - line 3, which is the line that works on UniServer, but not on Dreamhost. These tokens are implemented through cookies which are set and read in DreamHost, and does evaluate to ‘valid’, (isValid returns true), but on Dreamhost, it always sends the 404 video. I can put the $_GET[‘file’]; part in the else statement and the video will stream, so it’s not an issue of the file not being available.

The strange thing is that my work around leaves the code untouched, but simply changed the validation function to check a server-based cookie (I wrote the cookie information to a temp directory rather than sending it as a cookie) and it then works on DreamHost. But again, even when sending cookies, if I output the value of isValid on DreamHost, it evaluates as true, but line 3 doesn’t recognize it. It does recognize the same code using UniServer locally.

Am I looking in the right place? Or is this some issue with the way cookies are sent, received, and processed via the internet versus localhost? Maybe this is not an issue with DreamHost at all? The only thing I could think of was to compare phpinfo() on DreamHost and UniServer. There are some differences, but nothing I could see that might explain the discrepancy.

I’m also a novice PHPer, so be kind if I’m missing something obvious. For reference, the xmoovStream server documentation is here.

[php]
if (isset($_GET[‘file’]) && isset($_GET[‘token’])) {
$tokenHandler = new xsToken();
if($tokenHandler->isValid($_GET[‘file’], $_GET[‘token’])) {
$file = $_GET[‘file’];
}
else {
$file = FILE_404;
}

$position = isset ($_GET['start']) ? intval($_GET['start']) : 0;
$config = array
.
.
.

[/php]


#2

Well, since the issue seems to be with the isValid() function, why don’t you post that part?


#3

Good point… I didn’t want to overload you with code, but I guess that makes it difficult to troubleshoot.

Here’s the xsTokenClass:

[php]

<?php /* xmoovStream Token Handler Tokens are assigned to file names and saved in cookie on the clients computer. This system will not work correctly in the following cases: * Cookies are not enabled on the clients computer. * You are using tokens to serve videos to an iPhone */ define ('XS_KEY', '4b0a7'); define ('XS_TOKEN_EXPIRE', 3600); class xsToken { var $tokens = array(); function getKey ($file) { return md5($file.XS_KEY); } function getToken ($file) { $key = $this->getKey ($file); if (isset($this->tokens[$key])) { return $this->tokens[$key]; } else if (isset($_COOKIE[$key])) { return $_COOKIE[$key]; } return false; } function isValid ($file, $token) { if ($token == $this->getToken ($file)) { return true; } return false; } function setToken ($file) { $key = $this->getKey ($file); $token = md5(uniqid(rand(),1)); setcookie ($key, $token, time() + XS_TOKEN_EXPIRE,'/',FALSE); $this->tokens[$key] = $token; return $token; } } ?>

[/php]