RSS - Latest posts Posts Tagged ‘fix’

Home » Tags » fix
5Jun
2011

WordPress update permission issues

WordPress can often be such a pain to deal with…

Recently I was trying to get an installation updated as well as some of the plugins. What should have been a straightforward task, turned out to be several hours of messing around with permissions and trying to figure out why even 777 isn’t enough for the updates to NOT fail and what user should own what.

Well it turns out that it’s only partly the fault of WordPress as it is an issue with the FTP server. Still some better messaging would be helpful…

There were mentions about a patch and fixes in potentially in the 3.2 WP version related to the error I was getting:

Could not copy file.: /public_html/wp-admin/css/theme-editor.dev.css

However only after stumbling across this page I found an easy and quick solution.

Turns out it was enough to just switch from Pure-FTPD to Pro-FTPD.

Categories:

2Apr
2011

Top Level Cookies in Opera for Custom Domain Names

For our local development at work we all use the same fake domain – helps with setting API keys and other things across the board and isn’t hard to setup whatever system any new developer might have. It also happens to be not a “.com”: www.local.bnt – which is nice for not confusing it with real sites.

While developing cross-subdomain authentication we suddenly realised that it didn’t work on Opera. After a bit of research it turns out that it’s not the setting of the cookie path (“.local.bnt”) that is the problem, but the way Opera checks which part of the domain name is the top level domain:

“Here at Opera we went for the rule-of-thumb method: When Opera is checking a cookie whose target domain matches certain criteriea (e.g. it is not a .com domain), we do a DNS name lookup for the target domain, to see if there is an IP address for that domain. If there is an IP address for the domain (e.g. example.no) we assume that the domain is a normal company domain, not a co.uk like domain, and therefore safe. If there is no IP address we assume that the domain is co.uk-like and therefore unsafe, and only allows the cookie to be set for the server that sent the cookie.”

So that’s the problem right there and with an easy fix once you know the above… However the whole article is worth a read as it does shed some light on the multiple problems related to top level domains and cookies.

If you want to keep your random local domain name make sure your hosts file contains not only your sub domains, but the main one as well even if it is not used directly.

127.0.0.1    www.local.bnt
127.0.0.1    local.bnt

Categories:

30Jan
2011

Enable delayed messages in Zend_Queue

The default Zend_Queue DB implementation unfortunately does not allow you to pass a timeout value when saving a message on the queue. However not all is lost and you can easily extend the standard Zend classes to add that functionality.

All you need is your own Db adapter and Queue class.

For the adapter you only need to overwrite the send() function. The highlighted code below is the only change to the original class (2 lines affected…). You could actually apply this without extending Zend_Queue, but this way will be easier if you ever need to update your Zend library.

<?php

class TS_Queue_Adapter_Db extends Zend_Queue_Adapter_Db {

    /**
     * Send a message to the queue
     *
     * @param  string     $message Message to send to the active queue
     * @param  Zend_Queue $queue
     * @param  Timestamp $timeout
     * @return Zend_Queue_Message
     * @throws Zend_Queue_Exception - database error
     */
    public function send($message, Zend_Queue $queue = null, $timeout = null){
        if ($this->_messageRow === null) {
            $this->_messageRow = $this->_messageTable->createRow();
        }

        if ($queue === null) {
            $queue = $this->_queue;
        }

        if (is_scalar($message)) {
            $message = (string) $message;
        }
        if (is_string($message)) {
            $message = trim($message);
        }

        if (!$this->isExists($queue->getName())) {
            require_once 'Zend/Queue/Exception.php';
            throw new Zend_Queue_Exception('Queue does not exist:' . $queue->getName());
        }

        $msg = clone $this->_messageRow;
        $msg->queue_id = $this->getQueueId($queue->getName());
        $msg->created = time();
        $msg->body = $message;
        $msg->md5 = md5($message);
        $msg->timeout = $timeout;

        try {
            $msg->save();
        } catch (Exception $e) {
            require_once 'Zend/Queue/Exception.php';
            throw new Zend_Queue_Exception($e->getMessage(), $e->getCode(), $e);
        }

        $options = array(
            'queue' => $queue,
            'data' => $msg->toArray(),
        );

        $classname = $queue->getMessageClass();
        if (!class_exists($classname)) {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($classname);
        }
        return new $classname($options);
    }
}

Your Queue class only needs to extend the send() function again to allow you to pass the timeout through. obviously you can use this class to add other functionality too.

<?php

class TS_Queue extends Zend_Queue {

	/**
	 * Send a message to the queue
	 *
	 * @param  mixed $message message
	 * @return Zend_Queue_Message
	 * @throws Zend_Queue_Exception
	 */
	public function send($message, $timeout = null){
		return $this->getAdapter()->send($message, null, $timeout);
	}
}

Categories:

15Dec
2010

Installing Windows 7 Guest on VMWare 7 on OpenSuse 11.3 Host

Maybe this will help anyone else stuck on the installation.

For a long while my Windows 7 install inside VMWare 7 would get stuck at “expanding files 0%”. I kept thinking it was my machine and setup that was causing issue, after all a x64 tablet pc is not your most common config. Just in case anyone is curious I’ve got a Thinkpad x201t.

After trying both 32bit and 64bit Windows 7 version, upgrading my RAM from 4GB to 8GB and trying out changing the virtual disk location from ntfs to ext3 and back I was quickly running out of options.

Unfortunately VMWare support is extremely picky about your os versions and didn’t even try to suggest anything unless I downgraded to OpenSuse 11.2 – which was not an option due to certain driver compatibility.

Fortunately I decided to give it one more go and instead of using my external dvd drive for the Windows 7 installation I saved the DVD as iso and run the installation that way. And there you go, that was the solution!

My suspicion was the fact that my DVD drive is usb powered, however while looking for a solution I saw similar questions being asked for other linux hosts and no mention of external DVD drives, so it might be a more generic issue.

Categories:

9Dec
2010

PHP_AUTH_USER and PHP_AUTH_PW is null

Ok, so you’re trying to setup password protection on your website using HTTP authentication. Unfortunately despite the request for password working your authentication keeps failing. If you check the output of your script and the password and username variables are not populated as expected it will usually be for one of two reasons.

Working code example


$username = "expectedUsername";
$password = "expectedPassword";

if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $username || $_SERVER['PHP_AUTH_PW'] != $password) {
  header('WWW-Authenticate: Basic realm=""');
  header('HTTP/1.0 401 Unauthorized');
  echo '>h2>Authorization failed.>/h2>';
  exit;
} else if($_SERVER['PHP_AUTH_USER'] != $username & $_SERVER['PHP_AUTH_PW'] != $password){
  echo '>h2>Authorization failed.>/h2>';
  exit;
}

Most common reason for failure

Firstly if you are using an older book or website as reference you will see $PHP_AUTH_USER mentioned instead of $_SERVER['PHP_AUTH_USER']. If you are using the former then this could be the reason for not seeing your variables populated.

The reason that can take you by surprise

If your code is correct (compare against the example) and you are using the $_SERVER variable format and still getting NULL inside both $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] it’s time to check your server settings.

HTTP authentication does not work with the cgi version of PHP, so if your hosting allows you will need to switch to PHP as Apache module or look for an alternative solution.

Categories: