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
相关推荐
fs哆哆1 小时前
在VB.net中一维数组,与VBA有什么区别
java·开发语言·数据结构·算法·.net
johnZhangqi1 小时前
深圳大学-计算机信息管理课程实验 C++ 自考模拟题
java·开发语言·c++
Sally璐璐2 小时前
Go语言变量声明与初始化详解
java·开发语言·golang
写点啥呢2 小时前
Android为ijkplayer设置音频发音类型usage
android·音视频·usage·mediaplayer·jikplayer
luofeiju2 小时前
交叉编译笔记
开发语言
StudyWinter3 小时前
【C++】仿函数和回调函数
开发语言·c++·回调函数·仿函数
C4程序员3 小时前
北京JAVA基础面试30天打卡14
java·开发语言·面试
黑客影儿3 小时前
Go特有的安全漏洞及渗透测试利用方法(通俗易懂)
开发语言·后端·安全·web安全·网络安全·golang·系统安全
搬码临时工3 小时前
通过自定义域名访问内网的web服务和tcp应用:内网ip到局域网外域名访问过程
服务器·tcp/ip·php
你好,我叫C小白4 小时前
C语言 常量,数据类型
c语言·开发语言·数据类型·常量