【发布时间】:2013-01-10 09:21:37
【问题描述】:
我正在创建我的应用程序的移动版本。这是设置页面 (mysettings.php) 的一部分。
if(!isset($_SESSION['access_token']))
{
echo("<script type='text/javascript'> window.top.location.href='http://www.example.com/mobile/login.php'</script>");
}
如果 access_token 没有设置,那么它应该重定向到 login.php 但我不明白为什么它不起作用。
在渲染的源代码中我可以看到因为重定向没有发生是(重定向代码存在)
<script type='text/javascript'> window.top.location='http://www.example.com/mobile/login.php'</script>
<!DOCTYPE html>
<html>
<head>...
.
.
.</html>
我正在使用 Chrome,这是我登录到 mysettings.php 页面的源代码
<?php
session_start();
$logins=0;
?>
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Settings</h1>
</div><!-- /header -->
<div data-role="content">
<div class="ui-grid-a">
<div class="ui-block-a"><a href="mysettings.php" data-role="button" data-mini="true">Settings</a> </div>
<div class="ui-block-b"><a href="my.php" data-role="button" data-mini="true">My Pictures</a> </div>
</div>
</div><!-- /content -->
<div data-role="footer">
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>
【问题讨论】:
-
为什么不在 PHP 中执行重定向?
-
@AnthonyForloney:我该怎么做?
-
@AnthonyForloney:如果你指的是标题,那也没有用。我得到“未定义”作为源代码中的消息`
警告:无法修改标头信息 - 标头已发送(输出开始于 /home/earnfame/public_html/mobile/mysettings. php:7) 在 /home/xxx/public_html/mobile/mysettings.php 行 10
` 我正在尝试从 php 页面访问它是基于移动的。这会导致任何问题吗?
标签: javascript android html redirect http-redirect