PHP Code
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 functions to Apache handle.htpasswd file
?View Code PHP< ?php
/*
Author : Mitko Kostov
Weblog : http://mkostov.wordpress.com
Mail :mitko.kostov@gmail.com
Date : 12/21/2007
Used : PHP and Smarty
*/
// function to register user
function regUser() {
$filename = ‘members/password/.htpasswd’;
$data = $_POST[’username’].":".htpasswd($_POST[’password’])."\n";
[...]
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: [...]
A calendar code
This class can be used to display month calendars in HTML tables.
It takes a given month and year and generates an HTML table with the days of that month. The calendar start week day may be set to Sunday or Monday.
Special event days may exhibit the title of the event in the respective calendar table [...]
PHP read Excel
?View Code PHP
< ?php
/**
* <?php
* require "excel_class.php";
* Read_Excel_File("Book1.xls",$return);
* for ($i=0;$i<count($return[Sheet1]);$i++)
* {
* for ($j=0;$j<count($return[Sheet1][$i]);$j++)
* {
* echo $return[Sheet1][$i][$j]."|";
* }
* echo "<br>";
* }
* ?>
* < ?
* require "excel_class.php";
* Read_Excel_File("Book1.xls",$return);
* Create_Excel_File("ddd.xls",$return[Sheet1]);
* ?>
*/
define(’ABC_CRITICAL’, 0);
define(’ABC_ERROR’, [...]
I use frequently some PHP function
Before makes php the project development, uses frequently some functions, reorganize now, shares together with everybody
?View Code PHP< ?php
class function_class{
/**
* Get IP
*
* @return IP
*/
function GetIP() {
if ($_SERVER["HTTP_X_FORWARDED_FOR"]){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else if ($_SERVER["HTTP_CLIENT_IP"]){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
else if ($_SERVER["REMOTE_ADDR"]){
$ip = $_SERVER["REMOTE_ADDR"];
}
else if (getenv("HTTP_X_FORWARDED_FOR")){
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
else if (getenv("HTTP_CLIENT_IP")){
$ip = getenv("HTTP_CLIENT_IP");
}
else if (getenv("REMOTE_ADDR")){
$ip = getenv("REMOTE_ADDR");
}
else{
$ip = "Unknown";
}
return [...]
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 [...]
Has optimized PHP click number statistics code
Has optimized PHP click number statistics code
< ?php
error_reporting(E_ALL);
$ROOT_PATH = ‘../’;
include_once($ROOT_PATH . “include/config.php”);$update_time = 1800;//The refresh time, second
$article_id = (isset($_GET['article_id']) && is_numeric($_GET['article_id']) && $_GET['article_id'] > 0) ? intval($_GET['article_id']) : 0;
if ($article_id > 0) {
$filename = $ROOT_PATH . ‘log/click_log.txt’;
