PHP

09
Jan

Cron in CakePHP – website address and base url

Posted by eugene as PHP

If you have set Cron for CakePHP, then most likely you’ve read this guide. After following the described actions in it, everything works fine. But there’s a small problem with sending of mails, since consequently Cron is often used.

If you use the $this->Html->url() function in the mail templates by transmitting true as the second parameter in order to substitute the website address in the resulting line, while sending via Cron it will not happen. The reason of it – Cake cannot guess for which website the request has been implemented as there’s no request.

The resolution of this problem is a slight amendment of the file created in the above guide. After the line

define('CRON_DISPATCHER',true);
</pre
<p align="justify">Insert the lines
<pre lang="Java">
define('FULL_BASE_URL', 'http://site.com');
Configure::write('App.base', '/');

The first line defines the website address, the second line is needed personally in my server configuration. Full path has substituted in the address to the cron.php file without it.

23
Jul

PHP and FileReference in Flex

Posted by eugene as Flex, PHP

Authentication is necessary in any RIA application. Good it’s that making it is easy. The most common authentication is carried out on the server side and its results are recorded into the session parameters. It allows the user to request the authorization data only once for the entire work session with the application.

In conjunction of Flex and PHP, such a scheme works without any problem. All requests on the server side can be protected by authorization data in the PHP session. But if you try to check the authentication in the POST request of the file load handler from FileReference, it won’t work out. The session will be empty in the request handler.

The PHP session is getting connected with the browser session ID which is stored in the browser cookies. The problem is that when you request via FileReference cookies are not transmitted. As a result, PHP opens a new session.

To let PHP use an existing session, it is necessary to add the ID parameter to the current session. For example:

public function browse():void
{
	fileReference = new FileReference();
	fileReference.addEventListener(Event.SELECT, onDocumentSelected);
	fileReference.browse();
}
 
private function onDocumentSelected(event:Event):void
{
	getSession();
}
 
private function sessionRecieved(sessionId:String):void
{
	var url:String = "http://example.com?PHPSESSID=" + sessionId;
	var urlRequest:URLRequest = new URLRequest(url);
	fileReference.upload(urlRequest);
}

In the example, in the document selection handler the getSession() method is called which is requesting the session identifier from the PHP side. When the ID is received, the sessionReceived method is called which places the session IDs into the query line and initiates the file download. The session identifier is placed into the PHPSESSID parameter.

Also the identifier of the PHP session can be requested via JavaScript. But I do not like this option.