PHP 5.5 Action Management with Parameters (English Version)

PHP 5.5 Action Management with Parameters (English Version)

Here's a PHP 5.5 compatible script that uses URL parameters instead of paths for all operations:

php 复制代码
<?php
// Start session for persistent storage
session_start();

// Initialize the stored action if not set
if (!isset($_SESSION['stored_action'])) {
    $_SESSION['stored_action'] = null;
}

// Process requests based on parameters
if (isset($_GET['action'])) {
    // Store the action value
    $_SESSION['stored_action'] = $_GET['action'];
    echo "Action stored: " . htmlspecialchars($_GET['action']);
} elseif (isset($_GET['cmd'])) {
    $command = strtolower($_GET['cmd']);
    
    if ($command === 'status') {
        // Return the stored action value
        $action = $_SESSION['stored_action'];
        echo "Current action: " . ($action ? htmlspecialchars($action) : "No action stored");
    } elseif ($command === 'delete') {
        // Delete the stored action
        $_SESSION['stored_action'] = null;
        echo "Action deleted successfully";
    } else {
        echo "Invalid command";
    }
} else {
    // Display usage instructions
    echo "<h1>Action Management System</h1>";
    echo "<p>Usage:</p>";
    echo "<ul>";
    echo "<li>Add <code>?action=value</code> to store a value</li>";
    echo "<li>Add <code>?cmd=status</code> to view stored value</li>";
    echo "<li>Add <code>?cmd=delete</code> to delete stored value</li>";
    echo "</ul>";
    echo "<p>Examples:</p>";
    echo "<ul>";
    echo "<li><a href='?action=test_value'>?action=test_value</a></li>";
    echo "<li><a href='?cmd=status'>?cmd=status</a></li>";
    echo "<li><a href='?cmd=delete'>?cmd=delete</a></li>";
    echo "</ul>";
}
?>

How to Use

  1. Store an action value:

    • URL: yourscript.php?action=your_value
    • Example: yourscript.php?action=open_door
  2. Check stored value:

    • URL: yourscript.php?cmd=status
    • Will display the currently stored action
  3. Delete stored value:

    • URL: yourscript.php?cmd=delete
    • Clears the stored action

Key Features

  1. Uses URL parameters for all operations (action, cmd)
  2. Session-based storage persists between requests
  3. Full English interface and comments
  4. Input sanitization with htmlspecialchars()
  5. Case-insensitive command handling
  6. Clear usage instructions
  7. PHP 5.5 compatible

Security Notes

  • Always sanitize output with htmlspecialchars()
  • Session storage is more secure than using a global variable
  • Consider adding CSRF protection for production use
  • For sensitive data, consider database storage instead of sessions
相关推荐
zhaoyufei1339 分钟前
Android触屏TP驱动事件上报以及多点触摸
android
杨筱毅11 分钟前
【Android】详细讲解ViewDragHelper的实现原理(不含代码版)
android
云泽8082 小时前
函数模板与类模板:C++泛型编程核心解析
java·开发语言·c++
代码s贝多芬的音符8 小时前
ios android 小程序 蓝牙 CRC16_MODBUS
android·ios·小程序
应用市场8 小时前
构建自定义命令行工具 - 打造专属指令体
开发语言·windows·python
Dfreedom.8 小时前
一文掌握Python四大核心数据结构:变量、结构体、类与枚举
开发语言·数据结构·python·变量·数据类型
一半烟火以谋生8 小时前
Python + Pytest + Allure 自动化测试报告教程
开发语言·python·pytest
虚行8 小时前
C#上位机工程师技能清单文档
开发语言·c#
小羊在睡觉9 小时前
golang定时器
开发语言·后端·golang
CoderCodingNo9 小时前
【GESP】C++四级真题 luogu-B4068 [GESP202412 四级] Recamán
开发语言·c++·算法