PHP daily practical small Tips

Source: Internet
Author: User

1. Simple Determination of IP address Legality
2. email Regular Expression judgment
3. Check whether the IP address and mask are valid.
4. About form refresh
5. About form refresh
1. Simple Determination of IP address Legality
If (! Strcmp (long2ip (sprintf ("% u", ip2long ($ ip), $ ip) echo "is ipn ";
----
2. email Regular Expression judgment
Eregi ("^ [_. 0-9a-zA-Z-] + @ ([0-9a-zA-Z] [0-9a-zA-Z _-] +.) + [a-zA-Z] $", $ email );
----
3. Check whether the IP address and mask are valid.
$ Ip = '1970. 168.0.84 ';
$ Mask = '2017. 255.255.0 ';
$ Network = '1970. 100 ';
$ Ip = ip2long ($ ip );
$ Mask = ip2long ($ mask );
$ Network = ip2long ($ network );
If ($ ip & $ mask) = $ network) echo "valid ip and maskn ";
?>
----
4. Today we have solved a very depressing problem.
The add user page of ipb is toadduser. php seems to submit the statement repeatedly, so when a new user is added, it always reports that the user already exists... I have been depressed for three days, and I finally got it done. It's amazing!
----
5. About form refresh
Q: Why are all fields cleared after I click the back button of the browser?
A: This is because you have used the session_start function on your form submission page. This function forces the current page not to be cached. The solution is to add the header ("Cache-control: private") after your Session_start function. Note that your PHP program cannot have any output before this line.
Supplement: there is also a session-based solution, which is added before session_start.
Session_cache_limiter ('nocache'); // clear the form
Session_cache_limiter ('private'); // do not clear the form, only during the effective period of the session
Session_cache_limiter ('public'); // do not clear the form, as if the session is not used
You can add session_cache_limiter ("private, max-age = 10800") before session_start ");
From phpe.net
----
6. Get the output of the file download header quickly
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'
...... 11:50:30
----
7. Use the header to output the ftp download method and support resumable data transfer.
Example:
Header ('pragma: public ');
Header ('cache-Control: private ');
Header ('cache-Control: no-Cache, must-revalidate ');
Header ('Accept-Ranges: bytes ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.