//获取网上的一个文件function getUrlImage($url, $file = '', $maxExe = 0, $safe = false){ $urlExt = explode('.', $url); $fileExt = array('txt','jpg','gif','png'); if(!in_array(end($urlExt), $fileExt, true)) return false; $file = ($file)? $file.$urlExt : basename($url); $file = rand(1,1000).$file; ob_start(); //开启输出缓冲 set_time_limit($maxExe); //开启最大运行时间 readfile($url);//读入一个文件并写入到输出缓冲 $data = ob_get_contents(); ob_end_clean(); file_put_contents($file,$data); if($safe && is_executable($file)){//为安全起见,判定一下文件是否可执行 unlink($file); return false; } return $file;}getUrlImage('http://www.test.com/3675.jpg','newName');//批量生成cookiefunction mySetCookie($data, $name){ if(empty($data) || empty($name))return; $args = func_get_args(); $time = empty($args[2])? time() + 3600 : time() + $args[2]; $path = empty($args[3])? '' : $args[3]; $domain = empty($args[4])? '' : $args[4]; $secure = empty($args[5])? '' : $args[5]; if(is_array($data)){ foreach($data as $key => $val){ $full = "{$name}[$key]"; setcookie($full, $val, $time, $path, $domain, $secure); } }else{ setcookie($name, $data, $time, $path, $domain, $secure); }}$data = array('name' => '李四', 'age' => 15);mySetCookie($data,'userInfo');print_r($_COOKIE);//冒泡排序function arrSort(&$arr, $asc = ''){ $times = count($arr) - 1; for($i = 0; $i < $times; $i++){ for($j = 0; $j < $times - $i; $j++){ if($arr[$j] > $arr[$j + 1]){ $temp = $arr[$j]; $arr[$j] = $arr[$j + 1]; $arr[$j + 1] = $temp; } } } if('' != $asc) $arr = array_reverse($arr, false);//反转数组元素}//选择排序function seleSort(&$arr){ $times = count($arr) - 1; $jMax = count($arr); for($i = 0; $i < $times; $i++){ $min = $arr[$i]; $minId = $i; for($j = $i + 1; $j < $jMax; $j++){ if($min > $arr[$j]){ $min = $arr[$j]; $minId = $j; } } $temp = $arr[$i]; $arr[$i] = $arr[$minId]; $arr[$minId] = $temp; }}//插入排序function inserSort(&$arr){ $times = count($arr); for($i = 1; $i < $times; $i++){ $insert = $arr[$i]; $insertId = $i - 1; while($insertId >= 0 && $insert < $arr[$insertId]){ $arr[$insertId + 1] = $arr[$insertId]; $insertId--; } $arr[$insertId + 1] = $insert; }}//计算两个文件的相对路径。function relative_dir($fileA, $fileB){//A相当于B,所在目录 $aPath = explode('/',dirname($fileA)); $bPath = explode('/',dirname($fileB)); $bLen = count($bPath); $j = 1; for($i = 1; $i < $bLen; $i++){ if(isset($bPath) && isset($aPath)){ if($aPath[$i] == $bPath[$i]){$j++;}//累计相同路径部分 if($aPath[$i] != $bPath[$i]){$path .= '../';}//不同的,则增加退回上级 } } $path .= implode('/',array_slice($aPath, $j)).'/'.basename($fileA); return $path;}$a = 'a/b/c/test/5/8/aaa.php';$b = 'a/b/c/check/1/2/3/4/bbb.php';echo relative_dir($a,$b);//以附件方式实现文件下载:$file = 'e:/个人简历.doc';$file = iconv('utf-8', 'gb2312',$file);if(file_exists($file)){ $fname = basename($file); $fsize = filesize($file); header("Content-type:application/octet-stream");//二进制数据 header("Content-Disposition:attachment;filename={$fname}");//附件形式 header("Accept-ranges:bytes"); header("Accept-length:".$fsize); readfile($file);}else{ exit('flie not found!');}遍历一个目录,及其子目录:function recurDir($pathName){ $result = array(); $temp = array(); if(!is_dir($pathName) || !is_readable($pathName)) return null; $allFiles = scandir($pathName); foreach($allFiles as $fileName){ if(in_array($fileName, array('.','..')))continue; $fullName = $pathName . '/' . $fileName; if(is_dir($fullName)){ $result[$fileName] = recurdir($fullName); }else{ $temp[] = $fileName; } } foreach($temp as $f){ $result[] = $f; } return $result;}$pathName = 'D:\AppServ\www\zbseoag\\';print_r(recurDir($pathName));//从URL中获取文件扩展名: function getExt($url){ $arr = parse_url($url);//把URL解析成数组 $file = basename($arr['path']); $ext = explode('.',$file); return end($ext);}//PHP验证email格式function checkEmail($email){ $pattern = "/([a-z0-9]*[-_/.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[/.][a-z]{2,3}([/.][a-z]{2})?/i"; return preg_match($pattern,$email); }//文件上传<script>function addUpload(){ document.getElementById("upfiles").innerHTML += '<li>文件:<input type="file" name="files[]" /></li>';}function resetUpload(){ document.getElementById("upfiles").innerHTML = '<li>文件:<input type="file" name="files[]" /></li>';}</script><form action="" method="post" enctype="multipart/form-data" ><ul id="upfiles"><li>文件:<input type="file" name="files[]" /></li></ul><input type="submit" value="提交" /><input type="button" value="增加上传框" onClick="addUpload()" /><input type="button" value="重设上传框" onClick="resetUpload()" /></form>$files = 'files';//files是$_FILES中的一个元素数组,并所上传文件信息进行了归类$upDir = './upImg/';$fTypes = 'jpg|gif|txt|chm';function upFilse($files, $upDir, $fTypes){ if(isset($_FILES[$files]['name'])){ if(!is_dir($upDir)) mkdir($upDir, 0777, true) or exit('上传目录创建失败!'); $ftypeArr = explode('|',$fTypes); foreach($_FILES[$files]['name'] as $i => $value){ $fType = strtolower(end(explode(".",$_FILES[$files]['name'][$i]))); if(in_array($fType, $ftypeArr)){ $path = $upDir.time().$_FILES[$files]['name'][$i];//指定目录,且包含有文件名 move_uploaded_file($_FILES[$files]['tmp_name'][$i], $path);//移到指定目录 if($_FILES[$files]['error'][$i] == 0){ $file[$_FILES[$files]['name'][$i]] = $path; list($name, $path) = each($file);//each(数组)返回当前由键名与键值所构成的数组;list(变量1, 变量n 【或数组】) = 数字索引的数组,将值赋给变量。 $sql = "INSERT INTO `database`.`table`(name, path) VALUES ('$name', '$path')"; $msg[] = $value.'文件上传成功'; }else $msg[] = $value.'文件上传失败!'; }else $msg[] = $value.'文件格式不正确!'; } return $msg; }}print_r(upFilse($files, $upDir, $fTypes));//求今天是星期几:$time = getdate();//获取当前时间戳中的时间信息$weekday = array('星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');$wday = $time['wday'];//当前是一个星期中的第几天echo date("今天是:Y年m月d日H:i:s $weekday[$wday]");//求下周一是几月几日:$time = time();//当前时间戳$weekday = date('w');//当天的数字星期switch($weekday){ case 0: $nextMonday = $time+86400;break;//星期天则加一天 case 1: $nextMonday = $time+7*86400;break;//星期一,则加七天 case 2: $nextMonday = $time+6*86400;break; case 3: $nextMonday = $time+5*86400;break; case 4: $nextMonday = $time+4*86400;break; case 5: $nextMonday = $time+3*86400;break; case 6: $nextMonday = $time+2*86400;break;}echo date('Y-m-d',$nextMonday);//逐行读取文件指定行数的内容:function getRowData($file, $row = 0, mark = false){ $fhandle = fopen($file,'rb'); $row = ($row == 0)? filesize($file) : $row; while($row >0 && !feof($fhandle)){ $data[] = (mark)? fgets($fhandle) : fgetss($fhandle); $row--; } fclose($fhandle);}//读取文件指定字符长度function getLetterData($file, $num = 0, mark = false){ $fhandle = fopen($file,'rb'); $row = ($num)? filesize($file) : $num; $data = fread($fhandle, $num); fclose($fhandle);}//删除目录中在数据库中没有记录的图片public function delImg($data, $dir = '.'){ $files = scandir($dir); $delFiles = array_diff($allFiles,$data); foreach($delFiles as $name){ $file = rtrim($dir,'/').'/'.$name; unlink($file); echo $file.'<br/>'; }}

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.