《PHP编程最快明白》第四讲:日期、表单接收、session、cookie
实例11:日期戳、日期显示
复制代码 代码如下:
echo time();//返回一串以秒计算的时间数字戳
echo "
";
echo date("Y-m-d H:i:s",time()+8*3600);//格式化时间,+8*3600变为中国时区时间
echo "
";
$str="2010-08-24 10:26:10";
echo date("Y-m-d H:i:s",strtotime($str));//strtotime将字符串转为时间戳
echo "
";
?>
实例12:表单变量编码、接收
复制代码 代码如下:
echo $str=urlencode("第一页");//URL变量编码,跟google一样
echo "
".urldecode($str);//URL变量解码,我看到了
echo "
第一页";
echo "
";
if($_GET)echo "变量已接收:".$_GET['page'];//$_GET对应$_POST,PHP是自动识别URL编码并自动解码好的。
echo "
";
?>
实例13:session使用
复制代码 代码如下:
session_start();//session在浏览器关闭后马上失效,需要这样声明才能读写session
$_SESSION['id']='服务器';//这就是声明和初始化了,和数组用法一样
$_SESSION['name']='会话';
print_r($_SESSION);//会话注册成功输出一个数组
echo "
";
$_SESSION['id']='还是服务器';//改变一个会话,再输出看看
unset($_SESSION['name']);//注销一个会话,再输出看看
print_r($_SESSION);
echo "
";
?>
实例14:cookie使用
复制代码 代码如下:
setcookie("id","客户端");//这就是声明和初始化cookie的函数。关闭浏览器即失效
setcookie("name","会话",time()+3600);//自此1小时后失效
print_r($_COOKIE);//会话注册成功输出一个数组,也可以用$HTTP_COOKIE_VARS访问
echo "
";
setcookie("id","还是客户端");//改变一个会话,再输出看看
unset($_COOKIE['name']);//注销一个会话,再输出看看,等价于setcookie("name","",time()-1);这是很多书上说的,其实用unset也能注销
print_r($_COOKIE);
echo "
";
?>

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

With the popularity of the Internet, we use browsers to surf the Internet have become a way of life. In the daily use of browsers, we often encounter situations where we need to enter account passwords, such as online shopping, social networking, emails, etc. This information needs to be recorded by the browser so that it does not need to be entered again the next time you visit. This is when cookies come in handy. What are cookies? Cookie refers to a small data file sent by the server to the user's browser and stored locally. It contains user behavior of some websites.

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated
