gpt4 book ai didi

PHP 条件 - Javascript 重定向

转载 作者:行者123 更新时间:2023-11-30 13:05:20 25 4
gpt4 key购买 nike

我有一个 PHP“if”条件,如果为真,我想使用 javascript 将用户重定向到其他地方。但是它似乎不起作用,因为它总是重定向我,无论条件是否为真。

<?php
if (isset($_SESSION['lol'])) {
?><script type="text/javascript">
<!--
window.location = "http://www.test.org"
//-->
</script><?php
}
?>

这怎么可能?或者我怎样才能让它发挥作用?

最佳答案

只需在 PHP 中重定向即可:

<?
if (isset($_SESSION['lol']) {
header("Location: test.org");
}
?>

编辑:但是如果你想使用你当前的代码,你需要回显脚本标签:

<?
if (isset($_SESSION['lol'])) {
echo "<script>window.location.href = 'test.org';</script>";
}
?>

关于PHP 条件 - Javascript 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15882774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com