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
相关推荐
林烈涛4 小时前
js判断变量是数组还是对象
开发语言·前端·javascript
可可南木4 小时前
ICT 数字测试原理 3 --SAFETYGUARD 文件
开发语言·测试工具·pcb工艺
00后程序员张5 小时前
从零构建 gRPC 跨语言通信:C++ 服务端与
开发语言·c++
Komorebi_99995 小时前
Unocss
开发语言·前端
爱凤的小光5 小时前
图漾相机C++语言---Sample_V1(4.X.X版本)完整参考例子(待完善)
开发语言·c++·数码相机
Derrick__16 小时前
Python常用三方模块——Pillow
开发语言·python·pillow
蜀中廖化7 小时前
Android Studio 导入 opencv
android·opencv·android studio
奋斗的小鹰7 小时前
ASM Bytecode Viewer 插件查看kotlin和java文件的字节码
android·kotlin·asm
woshihonghonga7 小时前
【Ubuntu 20.04升级python3.9后终端打不开的bug】
linux·开发语言·python
王家视频教程图书馆7 小时前
C# asp.net模板代码简单API请求
开发语言·c#·asp.net