当前位置: 首页 > news >正文

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
// 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 instructionsecho "<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
http://www.xdnf.cn/news/1217683.html

相关文章:

  • 专业鼠标点击器,自定义间隔次数
  • 网站技术攻坚与Bug围剿手记
  • Spring Cloud『学习笔记』
  • [硬件电路-111]:滤波的分类:模拟滤波与数字滤波; 无源滤波与有源滤波;低通、带通、带阻、高通滤波;时域滤波与频域滤波;低价滤波与高阶滤波。
  • 《Java 程序设计》第 17 章 - 并发编程基础
  • 澳交所技术重构窗口开启,中资科技企业如何破局?——从ASX清算系统转型看跨境金融基础设施的赋能路径
  • 数据结构与算法:队列的表示和操作的实现
  • HighgoDB查询慢SQL和阻塞SQL
  • 模型优化——在MacOS 上使用 Python 脚本批量大幅度精简 GLB 模型(通过 Blender 处理)
  • 打车小程序 app 系统架构分析
  • 【12】大恒相机SDK C#开发 ——多相机开发,枚举所有相机,并按配置文件中的相机顺序 将所有相机加入设备列表,以便于对每个指定的相机操作
  • 深入理解 Slab / Buddy 分配器与 MMU 映射机制
  • 【源力觉醒 创作者计划】对比与实践:基于文心大模型 4.5 的 Ollama+CherryStudio 知识库搭建教程
  • mysql结构对比工具
  • 类与对象(上),咕咕咕
  • ECMAScript2024(ES15)新特性
  • SpringAI 1.0.0发布:打造企业级智能聊天应用
  • AI 安监系统:为工业园安全保驾护航
  • 【Debian】4-‌1 Gitea简介以及与其他git方案差异
  • Windows 10 WSLUbuntu 22.04 安装并迁移到 F 盘
  • 2018 年 NOI 最后一题题解
  • 【预判一手面试问题:排序】
  • 2023 年 NOI 最后一题题解
  • n8n为什么建议在数组的每个item中添加json键?
  • Docker部署Nacos
  • LeetCode 53 - 最大子数组和
  • Android Emoji 全面解析:从使用到自定义
  • 《嵌入式C语言笔记(十六):字符串搜索、动态内存与函数指针精要》
  • 企业微信API接口发消息实战:从0到1的技术突破之旅
  • MySQL索引和事务笔记