原解决ajax post提交 跨域 cors问题
解决ajax post提交 跨域 cors问题
在nginx配置文件中加
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers *;
注意:要在nginx中加,在php文件中加这些头是无效的.
…
记录-交流-Web开发知识分享
解决ajax post提交 跨域 cors问题
在nginx配置文件中加
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers *;
注意:要在nginx中加,在php文件中加这些头是无效的.
…
PHP session创建机制详解,PHP session是基于cookie的(一般是,如果客户端不支持cookie,则使用url query方式)。
PHP创建session代码:…
路由类
Router.php
<?php
class Router
{
    private $routes = [];
    private $routeCount = 0;
    public function addRoute($method, $url, $callback)
    {
        $this->routes[] = ['method' => $method, 'url' => $url, 'callback' => $callback];
        $this->routeCount++;
    }
    public function doRouting()
    {
        $is_match=0;
        // I …   网址的url结尾应该不应该带斜杠
带与不带斜杠"/"是不同的网址.
特别是相对url,
如果 你访问https://www.p2hp.com/about ,里面有个<a href="info">info</a>,则它将链接到https://www.p2hp.com/info.
而如果你访问https://www.p2hp.com/about/(一般返回同样的内容),则里面的<a href="info">info</a>,将链接到https://www.p2hp.com/about/info.
但根目录带不带/是一样的
如:http://www.p2hp.com 和http://www.p2hp.com/ 是一样的.
已测试.
参考:
https://blog.cdivilly.com/2019/02/28/uri-trailing-slashes
https://stackoverflow.com/questions/5948659/when-should-i-use-a-trailing-slash-in-my-url
https://www.cloudways.com/blog/trailing-slashes-urls/
https://ahrefs.com/blog/zh/trailing-slash/
…
向 nginx 发送非 GET,POST,HEAD请头(如PUT,PATCH请求),如果返回状态码为http 405 method Not Allowed
这通常是向根目录发送请求即"/" 或向静态html页面发送请求时会返回 405 Not Allowed.
向动态url发送请求,如php页面,则不会返回 405 Not Allowed.
…
PHP错误处理异常处理类,依赖Monolog.
<?php
use Monolog\Level;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class ErrorHandel
{
    private array $levels = [
        \E_DEPRECATED => "Deprecated",
        \E_USER_DEPRECATED => "User Deprecated",
        \E_NOTICE => "Notice",
        \E_USER_NOTICE => "User Notice",
        \E_STRICT => "Runtime Notice",
        \E_WARNING => "Warning",
        \E_USER_WARNING => "User …   websocket服务端与客户端代码示例. ( json socket )
用到了ws库.
npm install ws
创建websocket.mjs文件,写入以下代码:
import { WebSocketServer } from "ws";
const server = new WebSocketServer({ port: 3000 });
server.on("connection", (socket) => {
  // send a message to the client
  socket.send(JSON.stringify({
    type: "hello …   Swoole-Cli 或静态编译PHP 是一个 PHP 的二进制发行版,集成了 swoole、php 内核、php-cli、php-fpm以及多个常用扩展。Swoole-Cli 或静态编译PHP 是全部静态编译打包的,不依赖任何操作系统的so动态链接库,具备非常好的移植性,可以在任意 Linux 系统之间复制,下载即可使用。…
近期评论