当前位置: 首页 > 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.dtcms.com/a/307749.html

相关文章:

  • 知识随记-----使用现代C++客户端库redis-plus-plus实现redis池缓解高并发
  • python之使用ffmpeg下载直播推流视频rtmp、m3u8协议实时获取时间进度
  • 26.(vue3.x+vite)以pinia为中心的开发模板
  • 【RH134 问答题】第 11 章 管理网络安全
  • Git踩坑
  • Spring面试
  • wpf之ControlTemplate
  • ACL 2024 大模型方向优秀论文:洞察NLP前沿​关键突破!
  • SpringMVC核心原理与实战指南
  • C++游戏开发(2)
  • 解决Android Studio中创建的模拟器第二次无法启动的问题
  • Android Studio怎么显示多排table,打开文件多行显示文件名
  • Android Studio 中Revert Commit、Undo Commit 和 Drop Commit 使用场景
  • 【智能体agent】入门之--1.初体验
  • HighgoDB查询慢SQL和阻塞SQL
  • 微信小程序性能优化与内存管理
  • HTTP 请求头(Request Headers)清单
  • 【13】大恒相机SDK C#开发 —— Fom1中实时处理的8个图像 实时显示在Form2界面的 pictureBox中
  • MySQL 中的聚簇索引和非聚簇索引的区别
  • 淘宝 API HTTP/2 多路复用与连接优化实践:提升商品数据采集吞吐量
  • Ceph、K8s、CSI、PVC、PV 深入详解
  • TTS语音合成|f5-tts语音合成服务器部署,实现http访问
  • 【n8n】如何跟着AI学习n8n【03】:HTTPRequest节点、Webhook节点、SMTP节点、mysql节点
  • 【11】大恒相机SDK C++开发 ——原图像数据IFrameData内存中上下颠倒,怎么裁剪ROI 实时显示在pictureBox中
  • 5G毫米波射频前端设计:从GaN功放到混合信号集成方案
  • 初始sklearn 数据集获取、分类、划分与特征工程
  • mysql笔记02:DML插入、更新、删除数据
  • 【读书笔记】Design Patterns (1994)✅
  • 贝锐蒲公英X4 Pro 5G新品路由器:异地组网+8网口+双频WiFi全都有
  • 大模型005