在lock_url.php中,需要将$locked从字符串转换为整数,修复后代码如下:

<?php
$urls_file = 'urls.txt';

if (!isset($_POST['id']) || !isset($_POST['locked']) || !isset($_POST['password'])) {
	echo '缺少参数';
	exit;
}

$id = $_POST['id'];
$locked = (int) $_POST['locked'];
$password = $_POST['password'];

if (!file_exists($urls_file)) {
	echo '文件不存在';
	exit;
}

$urls = file($urls_file);
$urls = array_map('trim', $urls);

foreach ($urls as $index => $url) {
	$url_parts = explode('|', $url);
	$existing_id = md5($url_parts[0] . $url_parts[1] . (isset($url_parts[2]) ? $url_parts[2] : ''));

	if ($existing_id == $id) {
		if ($password != 'password') {
			echo '密码错误';
			exit;
		}

		$urls[$index] = "$url_parts[0]|$url_parts[1]|" . (isset($url_parts[2]) ? $url_parts[2] : '') . "|$locked";
		file_put_contents($urls_file, implode("\n", $urls));
		echo 'success';
		exit;
	}
}

echo '未找到对应的网址';
?>

通过将$locked强制转换为整数,可以确保锁定状态的正确保存,从而解决锁定按钮无法正常工作的问题。

修复网址收藏系统中锁定按钮无法正常工作的问题

原文地址: https://www.cveoy.top/t/topic/mPv0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录