PHP日常實用小Tips_PHP教程

來源:互聯網
上載者:User
1.簡易判斷ip地址合法性
2.email的正則判斷
3.檢測ip地址和mask是否合法的例子
4.關於表單重新整理
5.關於表單重新整理
1.簡易判斷ip地址合法性
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
----
2.email的正則判斷
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);
----
3.檢測ip地址和mask是否合法的例子
$ip = '192.168.0.84';
$mask = '255.255.255.0';
$network = '192.168.0';
$ip = ip2long($ip);
$mask = ip2long($mask);
$network = ip2long($network);
if( ($ip & $mask) == $network) echo "valid ip and maskn";
?>
----
4.今天解決了一個巨鬱悶的問題
ipb的添加使用者頁面toadduser.php似乎會重複提交,導致在添加新使用者的時候總是報該使用者已經存在...已經鬱悶了我3天了,終於搞定,大快人心!
----
5.關於表單重新整理
問:為什麼我在點擊瀏覽器的後退按鈕後,所有欄位的資訊都被清空了?
答:這是由於你在你的表單提交頁面中使用了 session_start 函數。該函數會強制當前頁面不被緩衝。解決辦法為,在你的 Session_start 函數後加入 header("Cache-control: private"); 注意在本行之前你的PHP程式不能有任何輸出。
補充:還有基於session的解決方案,在session_start前加上
session_cache_limiter('nocache');// 清空表單
session_cache_limiter('private'); //不清空表單,只在session生效期間
session_cache_limiter('public'); //不清空表單,如同沒使用session一般
可以在session_start();前加上session_cache_limiter("private,max-age=10800");
摘自phpe.net
----
6.快速搞定檔案下載頭部輸出
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo 'xxx'
.......2004-08-19 11:50:30
----
7.用header輸出ftp下載方式,並且支援斷點續傳
一個例子:
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Accept-Ranges: bytes');

http://www.bkjia.com/PHPjc/631816.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631816.htmlTechArticle1.簡易判斷ip地址合法性 2.email的正則判斷 3.檢測ip地址和mask是否合法的例子 4.關於表單重新整理 5.關於表單重新整理 1.簡易判斷ip地址合法性 if(!str...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.