Time of Update: 2017-01-13
使用lvs或者nginx進行web的負載平衡時,一般都會遇到session共用的問題,因為一般PHP網站的session是以檔案的形式儲存於伺服器本地的硬碟上。多個伺服器進行負載平衡時,將會出現使用者請求被分配到其他伺服器上後session丟失的問題。解決方案主要有以下幾個思路。1.將session儲存在共用的裝置上,例如NFS等檔案系統上這種解決方案很容易實現,無需做特殊設定,將nfs目錄mount至php的session儲存目錄即可。缺點是NFS依託於複雜的安全機制和檔案系統,因此並發效率不
Time of Update: 2017-01-13
今天分享一段PHP中多張圖片合成一張圖片的代碼實現,我們可以在圖片合成,浮水印,九宮格等需求下使用到類似這樣的圖片合成效果,下面一起來看看例子吧。例子 代碼如下複製代碼 $imgs = array();$imgs[0] = '1.jpg';$imgs[1] = '2.jpg';$imgs[2] = '3.jpg';$imgs[3] = '4.jpg';$target = 'emp.jpg';//背景圖片$target_img =
Time of Update: 2017-01-13
Regex提取網址中的id 代碼如下複製代碼 preg_match('/http://t.sina.com.cn/(d+)/fans//',$html,$result); Regex提取網址中的idecho $result[1]; PHP的Regex提取圖片地址的代碼。 代碼如下複製代碼 $str='<p style="padding: 0px; margin-top: 0px; margin-bottom: 0px;
Time of Update: 2017-01-13
引用檔案的方法有兩種:require 及 include。兩種方式提供不同的使用彈性。require 的使用方法如 require("MyRequireFile.php"); 。這個函數通常放在 PHP 程式的最前面,PHP 程式在執行前,就會先讀入 require 所指定引入的檔案,使它變成 PHP 程式網頁的一部份。常用的函數,亦可以這個方法將它引入網頁中。include 使用方法如 include("MyIncludeFile.php");
Time of Update: 2017-01-13
代碼如下複製代碼 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html
Time of Update: 2017-01-13
本文介紹了使用jQuery、PHP和MySQL實作類別似360安全衛士防火牆開啟關閉的開關,可以將此功能應用在產品功能的開啟和關閉功能上。準備工作為了更好的示範本例,我們需要一個資料表,記錄需要的功能說明及開啟狀態,表結構如下:CREATE TABLE `pro` ( `id` int(11) NOT NULL auto_increment, `title` varchar(50) NOT NULL,
Time of Update: 2017-01-13
create_code.php代碼 代碼如下複製代碼 <?phpsession_start();//產生驗證碼圖片header("Content-type: image/png");// 全數字$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,f,g"; //要顯示的字元,可自己進行增刪$list = explode(",",
Time of Update: 2017-01-13
function sendfile($myFile){ $mm_type="application/octet-stream"; $fp = fopen($myFile,'rb'); $size = filesize($myFile); ob_start(); header("Cache-Control: public, must-revalidate"); header("
Time of Update: 2017-01-13
function getServerName() { $ServerName = strtolower($_SERVER['SERVER_NAME']?$_SERVER['SERVER_NAME']:$_SERVER['HTTP_HOST']); if( strpos($ServerName,'http://') ) { return
Time of Update: 2017-01-13
php explode 執行個體與教程array explode ( string separator, string string [, int limit] )separator 必需。規定在哪裡分割字串。 string 必需。要分割的字串。 limit 可選。規定所返回的數組元素的最大數目。每個元素都是 string 的一個子串,它們被字串 separator 作為邊界點分割出來。如果設定了 limit 參數,則返回的數組包含最多 limit 個元素,而最後那個元素將包含 string
Time of Update: 2017-01-13
<?phptry{ /*** Read in the animated gif ***/ $animation = new Imagick("animation.gif"); /*** Loop through the frames ***/ foreach ($animation as $frame) &
Time of Update: 2017-01-13
完整php 檔案上傳類class UploadFile { /** * 允許的上傳檔案類型 * @var array $allowFileTypes * @access private */ private $allowFileTypes = array('jpeg','jpg','gif','bmp','png'); /** * 允許的上傳檔案大小,單位位元組 * @var int
Time of Update: 2017-01-13
<?php/*** an array of attributes about a dog ***/$array = array('animal'=>'dog', 'name'=>'Offenbach', 'owner'=>'Mr Smith');/*** add the dogs favourite food to the array ***/$array = ($array, 'food', 'postmans leg');/*** print the array **
Time of Update: 2017-01-13
代碼如下複製代碼 preg_match_all("/<a(.*?)href=(.*?)</a>/i",$webContent,$link); $urls =array(); foreach($link[0] as $value) { if(strstr($value,'http') ) { if(strstr($value, $ex[
Time of Update: 2017-01-13
假如使用 iconv() 函數轉換編碼就相比比較簡單了,不過很多虛擬機器主機裡並不支援這個組件,我在網上找半天,才找到一個gb2312轉utf-8的方法,但不能逆向轉換。這個函數如下:/*******************************//GB轉UTF-8編碼*******************************/function gb2utf8($gbstr) {global $CODETABLE;if(trim($gbstr)=="") return
Time of Update: 2017-01-13
php 擷取檔案大小函數與執行個體教程<?php function getFileSize($url){ $url = parse_url($url); if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){ fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1rn");
Time of Update: 2017-01-13
php 檔案上傳代碼,限制jpg檔案<?php /* 圖片上傳類 www.lost63.com原創代碼 僅限JPG格式圖片 */ class uploadFile { var $inputName; //input名稱
Time of Update: 2017-01-13
php 入門型-檔案上傳代碼<?php if(!empty($_FILES["uploadImage"])) { // get file name $filename = basename($_FILES['uploadImage']['name']); // get extension $ext =
Time of Update: 2017-01-13
<?phpclass My_Lib_upfile{ var $upfile, $upfile_name, $upfile_size; # $upfile 臨時檔案名稱 $_FILES['tmp_name'] ,$upfile_name 檔案名稱 $_FILES['name'] ,$upfile_size 檔案大小$_FILES['size']; var $new_upfile_name; # 上傳後的檔案名稱 ; var $
Time of Update: 2017-01-13
function testAddslashes($array) { if(!get_magic_quotes_gpc()) { if(is_array($array)) { foreach($array as $key => $val) { $array[$key] = testAddslashes($val); } }