Latest article
How to ban ip access in php-PHP problem
How to ban ip access in php: 1. Prohibit access to a certain ip or ip address segment through the “” method; 2. Disable a single ip through the die method That’s it. Recommendation: “PHP Video Tutorial” How PHP prohibits access to an ip or ip address segment Disable a single ip as follows: The ban.dat file is as follows: BEGIN: 119.184.251.245 127.0.0.1 192.168.1.100 Disable the ip segment as follows: The above is the detailed content of how php prohibits ip access. For more information, please pay attention to other related articles on 1024programmer.com!
How to solve the problem of garbled characters in php file upload-PHP problem
The solution to uploading garbled characters in php files: first open the php file; then add the code “header(“Content-type: text/html; charset=utf-8″);” at the head of the php file Can. html is the page submitted by the form, php is the file for processing the form, upload is the location where the uploaded file is placed post html: File upload php: $file = $_FILES[“file”]; if ($file[“error”] > 0) { echo “Error: ” . $file[“error”]; } else { echo “File name: ” . $file[“name”] . “”; echo “File type: ” . $file[“type”] . “”; echo “File size: ” . ($file[“size”] / 1024) . “K”; echo “The location where the file is temporarily stored: ” . $file[“tmp_name”] . “”; //Save the uploaded file if (file_exists(“upload” . $file[“name”])) { echo $file[“name”] . “The file already exists”; } else { //If the directory does not exist, upload the file move_uploaded_file($file['tmp_name'], “upload/” . $file[“name”]); echo & # 39; File uploaded successfully! & # 39;; } } I uploaded a .txt file, as follows: The file uploaded at this time is what we want, but there are garbled characters The situation, um, okay, let’s solve it: First, add such a piece of code at the head of…
How to solve the phpjs garbled problem-PHP problem
The garbled characters in php js are because the encoding of the front-end html page is inconsistent with that of the background control page. The solution is to set php through the “header(“Content-type:text/html;charset:utf-8″)” Just encode. Example In this way, in other places on the page, you can directly refer to the js method output in php. The garbled code problem when the php page uses the echo js code When php is used as the control script of the html front-end page, it is often necessary to display something in the foreground. For example, use echo output. Recently, there is such a demand in the project. I used the code like echo “”, and the local debugging is completely normal, but when it is deployed to the server, the js output to the foreground displays garbled characters. I found it on the Internet, and some people said that it can be set, but after setting it like this, I found that the problem still exists. Analysis, the reason why garbled characters exist is that the page encoding is inconsistent with the browser display encoding, or in other words, the front-end HTML page is inconsistent with the background control page encoding.…
How to solve the PHP query garbled problem-PHP problem
The solution to PHP query garbled characters: first add “charset=utf-8” to the PHP page; then add “mysql_query(“set names & # 39; utf8 & # 39;”); ” statement is enough. Recommendation: “PHP Video Tutorial” PHP connection to MySQL query results Chinese display garbled solution We first assume that the encoding used in the database is UTF-8 At this time, we should first add The code is as follows in the PHP page: pre class=”brush:php;toolbar:false”> The charset value utf-8 here must be the same as the encoding type when the file is saved Add it before the database query The code is as follows: mysql_query(“set names 'utf8'”); The encoding value of the line statement should also be the same as the encoding value above. All in all, the encoding type saved on the webpage, the charset=utf-8 of the webpage, and the encoding method of the executed set names utf8 statement should be consistent A good analysis is quoted below Analysis of MySQL’s “SET NAMES x” character set problem Recently, I received training from BBT to make a voting system. The system code is not very difficult, but my time is mainly spent on researching character sets and encodings. The encoding (character set)…
Detailed usage of phpforeach-PHP problem
Usage of php foreach: 1. Use the syntax “foreach (array_expression as $value)”; 2. Use the syntax “foreach (array_expression as $key => $value)”. Recommendation: “PHP Video Tutorial” The usage and examples of foreach in PHP It is often used in PHP The use of foreach will be used, and to use foreach, an array must be used. Therefore, in this article, we will talk about arrays and foreach at the same time. foreach has two syntaxes: The first one: traverse the given array statement array_expression array. Each time through the loop, the value of the current element is assigned to $value and the pointer inside the array is moved forward by one step (so the next iteration will get the next element). foreach (array_expression as $value) Second: Same as above, while the key of the current unit The name will also be assigned to the variable $key each time through the loop. foreach (array_expression as $key => $value) Let’s explain one by one below ! 1. One-dimensional ordinary array and foreach Let’s write a one-dimensional array first, as follows: $a = array('Tom','Mary','Peter','Jack'); 1. We use the first foreach method to output. foreach ($a as $value) { echo $value.””; } The final…
What to do if php Chinese output is garbled – PHP problem
php mysql Write your review! Let’s make a fuss, see everything Member Login | User Registration recommended reading web how to install posix in php Guide: The programming notes in this article will introduce to you the relevant content about how to install posix in php. I hope it will be helpful to you. Let’s take a look. A list of the contents of this article: 1. PHP such as… [detailed] Crayon Shinchan 2023-08-24 16:21:36 jsp The number of oracle query table fields In mysql, you can view the number of table fields by desc table name. It can be in oracle, there is no such syntax. The solution is to use the following statement: select count(1) from user_col_ … [detailed] Crayon Shinchan 2023-08-24 16:21:04
How does php replace the last character – PHP question
How to replace the last character in php: first create a PHP sample file; then use the regular expression “preg_replace('#.$#i', '0', $image_path);” just replace the last digit of the string. $image_path = 'http://www.baidu.com/1' ; $str = preg_replace('#.$#i', '0', $image_path); the content to be replaced by the second parameter Change 1 to 0 The above is the detailed content of how php replaces the last character. For more, please pay attention to other related articles on 1024programmer.com!
Why can a member method in a DB class in PHP be used as a static method! ask for advice
Why can a member method in a DB class in PHP be used as a static method! Ask for advice? This is a db.php file, which contains a DB class class DB { function &object() { static $db; if (empty($db)) { $db = new pgsql(); } return $db; } function query($sql, $transaction = false) { $db = & DB::object(); return $db->query($sql, $transaction); } } What I want to ask is that none of the methods in the DB class are static (static), why can it be used like DB::query() in an external PHP file, and DB::object() used in its own interior, I’m wondering why? Isn’t it just a static method? ? Ask God for some advice! ! Thanks in advance! ——Solution ——————-This is php4 code php4 doesn’t have so many constraints ——Solution ——————–php5 can conditionally accept php4——Solution—————- —-php 5.2 is basically the same as php4, except that objects are always passed by reference, that is, there is no need to use declarations & PHP 5.3 When E_STRICT level error checking is turned on, non-static methods cannot be used statically PHP 5.4 turns on E_STRICT level error checking by default, and non-static methods cannot be used in a static way
How to solve the mssqlphp garbled problem-PHP problem
The solution to mssql php garbled characters: 1. Modify the php.ini file and set the utf-8 encoding; 2. Use the iconv function to convert the encoding; 3. Use the Ado connection to set the encoding when connecting; 4. Add The meta attribute “”. Recommendation: “PHP Video Tutorial” The solution to garbled characters in php query mssql When php connects to mssql, all the queries are garbled characters. I know this kind of problem is a coding problem based on experience. Let me summarize the solution for you. Method one, modify php.ini The file, of course, can be set according to your page situation and can also be utf-8 encoded, the code is as follows: The code is as follows: ; mssql.charset = “ISO-8859-1” mssql.charset = “GBK” Method two, convert directly in the program, the code is as follows: The code is as follows: iconv('GB2312','UTF-8',$data) Method 3, use Ado connection to set the encoding when connecting, the code is as follows: The code is as follows: $cOnn= new COM(“ADODB.Connection”, NULL, CP_UTF8) or die(“Cannot start ADO”); PHP example, the code is as follows: The code is as follows: <?php //print("The next line generates an error.www.jb51.net”); //printaline(“PLEASE?”); //print(“This will not be displayed due…