PHP Development

Using sockets in PHP : Get articles from Usenet

http://www.phpbuilder.net/columns/armel20010427.php3
PHP can open sockets on remote or local hosts. Here is a hands-on example of using such a socket: getting connected to a Usenet News Server, talking to this server, and downloading some articles for a precise newsgroup.
Opening a socket in PHP
Sockets are opened using fsockopen(). This function is both available in PHP3 and PHP4. [...]


Simple PHP Cache Manager Class

This class can be used to cache arbitrary data in files.
It can check if the cache with a certain key already exists. If it exists and it is not expired, it can return the cached data. Otherwise it can store newly generated data in a cache file with the given key.
The class can be configured [...]


PHP Cookie Handler Class

This class allows for the handling of normal and serialized cookies as well as switching between these types of cookies.
Cookie Functions:
Write Cookies
Read Cookies
Delete Cookies
Use of this class is fairly simple.
Step 1: Include the class source in your php project using the require or include statement.
Step 2: Instance the cookie class by using the new keyword. [...]


PHP generate new an resizing image

?View Code PHP< ?PHP
class HanroadClass
{
/************************
generate new an Resizing image by the PHP GD library
Support picture format: jpg, gif, png
$source_img: Source image path
$target_dir: Target image path
$target_name: Target image name
$new_width: Target image width
$new_height: [...]


Custom Form Helpers in Solar

Another thing that Solar makes easy is the creation of custom form helpers. These can be anything outside of the usual input types (like text, checkbox, textarea, etc) and can be used to make helpful, more complex inputs for your app.
In a previous post, I worked some with the Solar_Form class to create a login [...]


Being Binary in SOAP

Well, it might not be the best way to do it, but here’s a way I found to send binary data via PHP’s SOAP extension from one place to another:
Server:

?View Code PHPfunction recieveFile($data){
$data=base64_decode($data);
$path=’/my/file/path/img_out.gif’;
$fp=fopen($path,’w+’);
if($fp){ fwrite($fp,$data); fclose($fp); }
return strlen($data).’written’;
}
$input = file_get_contents(”php://input”);
$server = new SoapServer(’http://[my url here]/binary.wsdl’,array(’encoding’=>’ISO-8859-1′));
$server->addFunction(’recieveFile’);
$server->handle();

and the Client:

?View Code PHPini_set("soap.wsdl_cache_enabled", "0");
//send binary data
$client=new SoapClient(’http://[my url here]/binary.wsdl’,array(’encoding’=>’ISO-8859-1′));
$data=file_get_contents(’/my/file/path/img_to_send.gif’);
$ret=$client->recieveFile(base64_encode($data));
print_r($ret);
[/code]
 
It’s pretty [...]


Debugging PHP code using debug_backtrace

Most of the PHP developers debug php code in their local machine just by trial and error using “print_r”,”var_dump” and “echo”. They dont write unit tests or follow any advanced debugger like xdebug. But the problem of using these methods is you cannot fool proof your code and their might be some bugs still present [...]


5 Ways to be a Better PHP Developer

Often, an inexperienced PHP developer will hop onto IRC and ask a question in ##php on Freenode. And if the question is trivial, the answer seems obvious or they simply seem like a newbie, they may soon find themselves bombarded with such comments as “RTFM”, “Go learn PHP”, “We are not your personal tutors” or [...]


Uses KSES to filter the data-in safely

The safe first principle is never needs to believe any exterior data in PHP! How effective achieves this is one of each development personnel’s difficult. Before has not used webeditor, this basically quite good processing.
But if has used webeditor, how to guarantee that the user the data, simultaneously achieves safely (for example prevents the XSS [...]


Raises the efficiency in PHP mode through the factory pattern [reprint]

  Conducting large-scale system development time, I always worry whether it should include every possible use of the class library document.
        If it is included in use, the development will bring great trouble. Because I am impossible to know in advance which place will use which kind. Moreover, if each page, in accordance with the [...]