Time of Update: 2016-07-25
PHP驗證碼實現原理 產生隨機數或者字母儲存到session中(驗證驗證碼的時候用),然後對產生的數字或者字母進行繪圖!然後呈現在我們眼前 重新整理驗證碼:用js改變驗證碼圖片所帶的參數,讓瀏覽器不讀緩衝的圖片,從而實現重新整理驗證碼效果! 程式碼範例$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890";
Time of Update: 2016-07-25
這是最簡單的圖片驗證碼: image.php header("Content-type: image/png");$string = "abcdefghijklmnopqrstuvwxyz0123456789";for($i=0;$i $pos = rand(0,36); $str .= $string{$pos};}$img_handle = ImageCreate (60, 20) or die ("Cannot Create image");//Image size
Time of Update: 2016-07-25
下面的例子裁切圖片的左上方的100x100的部分。可以通過修改$src_x,$src_y,$src_w,$src_h的值來修改裁剪的範圍。 $filename= "test.jpg"; list($w, $h, $type, $attr) = getimagesize($filename); $src_im = imagecreatefromjpeg($filename); $src_x = '0'; // begin x $src_y = '0'; //
Time of Update: 2016-07-25
escape函數 /** * js escape php 實現 * @param $string the sting want to be escaped * @param $in_encoding * @param $out_encoding */ function escape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') { $return = '';
Time of Update: 2016-07-25
bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] ) explain:This requires that you place calls to this function prior to any output,
Time of Update: 2016-07-25
PHP 允許我們從指令碼直接寄送電子郵件。 mail() 函數 mail() 函數用於從指令碼中寄送電子郵件。 文法: /*** to:必需。規定 email 接收者。* subject:必需。規定 email 的主題。注釋:該參數不能包含任何新行字元。* message:必需。定義要發送的訊息。應使用 LF (\n) 來分隔各行。* headers:可選。規定附加的標題,比如 From、Cc 以及 Bcc。應當使用 CRLF (\r\n) 分隔附加的標題。*
Time of Update: 2016-07-25
function check_html($html) { preg_match_all("/]*>/",$html,$start_tags); preg_match_all("//", $html, $end_tags); if(count($start_tags[1]) != count($end_tags[1])) return false; for($i = 0; $i if(!in_array($start_tags[1][$i],
Time of Update: 2016-07-25
// 說明:擷取完整URLfunction curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" .
Time of Update: 2016-07-25
$databasehost = "localhost";$databasename = "test";$databasetable = "sample";$databaseusername ="test";$databasepassword = "";$fieldseparator = ",";$lineseparator = "\n";$csvfile = "filename.csv";/********************************//* Would you like
Time of Update: 2016-07-25
很多網站上的投票依據是ip地址,不同的ip地址一天可投票一次 下面的代碼就是利用curl擴充來偽造ip地址 達到無限制投票; $times = $_POST['times']; //投票次數 $url = $_POST['url']; //投票地址[某個選手下方投票按鈕的連結] while ($times) { $ip1 =
Time of Update: 2016-07-25
set_time_limit(0); // Supports all file types // URL Here: $url = 'http://somsite.com/some_video.flv'; $pi = pathinfo($url); $ext = $pi['extension']; $name = $pi['filename']; // create a new cURL resource $ch = curl_init(); // set URL and other
Time of Update: 2016-07-25
/**二分尋找:尋找一個值在數組中的位置* @$arr:操作的數組,前提是按順序排列* @$val:尋找的值* @$low:尋找的起始位置,預設從數組的第一個數找起* @hight:尋找的結束位置**/function binarySearch($arr, $val, $hight, $low=0){ while($low $mid = ceil($low + ($hight - $low) / 2); if($arr[$mid] == $val){
Time of Update: 2016-07-25
//擷取某個月的最後一天或某個月的天數function getMonthLastDay ( $month, $year ){switch ( $month ){case 4 :case 6 :case 9 :case 11 :$days = 30;break;case 2 :if ( $year % 4 == 0 ){if ( $year % 100 == 0 ){$days = $year % 400 == 0 ? 29 : 28;}else{$days = 29;}}else{$days =
Time of Update: 2016-07-25
php中可以通過設定header的content-type,強制使用者下載內容,而非直接在瀏覽器中開啟,如下代碼實現: downloadFile.php $filename = $_GET['file']; //Get the fileid from the URL// Query the file ID$query = sprintf("SELECT * FROM tableName WHERE id =
Time of Update: 2016-07-25
function random_readable_pwd($length=10){ // the wordlist from which the password gets generated // (change them as you like) $words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,'; $words .= 'green,blue,music,movies,radio,green,turbo,';
Time of Update: 2016-07-25
date_default_timezone_set('PRC');// 設定時區$date1 = strtotime('2015-01-01'); //把日期轉換成時間戳記$date2 = time(); //取目前時間的時間戳記$nowtime=strftime("%Y-%m-%d",$date2); //格式化輸出日期$days=round(($date1-$date2)/3600/24); //四捨五入echo "今天是".$nowtime."";echo
Time of Update: 2016-07-25
//PHP(前提是裝了curl):$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, "http://www.xxx/");curl_setopt ($ch, CURLOPT_REFERER, "http://www.xxx/");curl_exec ($ch);curl_close ($ch);//PHP(不裝curl用sock)$server = 'blog.qita.in';$host =
Time of Update: 2016-07-25
class User { static function getInstance() { if (self::$instance == NULL) { // If instance is not created yet, will create it. self::$instance = new User(); } return self::$instance; } private function __construct() //
Time of Update: 2016-07-25
PHP頁面跳轉一:header()函數 header()函數的定義如下: void header (string string [,bool replace [,int http_response_code]]) //重新導向瀏覽器 header(“Location: http://blog.csdn.net/abandonship”); PHP頁面跳轉二、Meta標籤
Time of Update: 2016-07-25
$start_time = '';$end_time = ''; switch ($type) { case 'thisWeek'://本周 $start_time = date("Y-m-d H:i:s",strtotime("-0 week Monday")); $end_time = date("Y-m-d H:i:s",strtotime("-0 week Sunday")); break; case