Forum Bugs

PHP windows command line arguments

JamesSas
Greetings,
I'm using the latest version of the PHP5 Prince class. setBaseUrl and setLog were not working on my dev box (Win32). This is because the getCommandLine() function adds single quotes around these arguments. This is also the case for the http user and password arguments, though i'm not using them. I've wrapped the arguments in a call to escapeshellarg() and all is well.

private function getCommandLine()
    {
	$cmdline = $this->exePath . ' --server ' . $this->styleSheets;

	if ($this->isHTML)
	{
	    $cmdline .= '--input=html ';
	}

	if ($this->baseURL != '')
	{
	    $cmdline .= "--baseurl=" . escapeshellarg($this->baseURL) . " ";
	}

	if ($this->doXInclude == false)
	{
	    $cmdline .= '--no-xinclude ';
	}

	if ($this->httpUser != '')
	{
	    $cmdline .= "--http-user=" . escapeshellarg($this->httpUser) . " ";
	}

	if ($this->httpPassword != '')
	{
	    $cmdline .= "--http-password=" . escapeshellarg($this->httpPassword) . " ";
	}

	if ($this->logFile != '')
	{
	    $cmdline .= "--log=" . escapeshellarg($this->logFile) . " ";
	}

	if ($this->embedFonts == false)
	{
	    $cmdline .= '--no-embed-fonts ';
	}

	if ($this->compress == false)
	{
	    $cmdline .= '--no-compress ';
	}

	if ($this->encrypt)
	{
	    $cmdline .= '--encrypt ' . $this->encryptInfo;
	}

	return $cmdline;
    }


The same goes for the styleSheets array. Although added with double-quotes, using escapeshellarg() is a safer method. Hope this helps someone.
mikeday
Thanks, we'll have to change this in the next release of the PHP wrapper.