在 lock_url.php 中,需要添加以下代码来判断网址是否已被锁定:

$url_parts = explode('|', $url);
if (isset($url_parts[3]) && $url_parts[3] == '1') {
	echo '该网址已被锁定';
	exit;
}

完整的 lock_url.php 代码如下:

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

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

$id = $_POST['id'];
$locked = $_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 (isset($url_parts[3]) && $url_parts[3] == '1') {
			echo '该网址已被锁定';
			exit;
		}

		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 '未找到对应的网址';
?>
修复网址收藏系统锁定按钮后无法修改和编辑的 Bug

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

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