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
相关推荐
长不大的蜡笔小新6 小时前
掌握NumPy:ndarray核心特性与创建
开发语言·python·numpy
Yue丶越6 小时前
【C语言】深入理解指针(三)
c语言·开发语言
恋猫de小郭6 小时前
Dart 3.10 发布,快来看有什么更新吧
android·前端·flutter
luoganttcc6 小时前
已知 空间 三个 A,B C 点 ,求 顺序 经过 A B C 三点 圆弧 轨迹 ,给出 python 代码 并且 画出图像
c语言·开发语言·python
今天的砖很烫6 小时前
ThreadLocal 结构设计的精妙之处
java·开发语言
Q_Q5110082856 小时前
python+django/flask的图书馆管理系统vue
spring boot·python·django·flask·node.js·php
麦麦鸡腿堡6 小时前
Java_HashMap底层机制与原码解读
java·开发语言·jvm
草莓熊Lotso6 小时前
C++ 抽象类与多态原理深度解析:从纯虚函数到虚表机制(附高频面试题)
java·运维·服务器·开发语言·c++·人工智能·笔记
再玩一会儿看代码6 小时前
Ken的Java学习之路——Java中关于面向对象
java·开发语言·经验分享·python·学习
迦蓝叶6 小时前
通过 HelloWorld 深入剖析 JVM 启动过程
java·开发语言·jvm·aot·启动过程·helloword·leyden