0

I am creating a mobile version of my application . This is a part of the settings page (mysettings.php).

 if(!isset($_SESSION['access_token']))
     {
        echo("<script  type='text/javascript'> window.top.location.href='http://www.example.com/mobile/login.php'</script>");
     }

If the access_token is not set then it should redirect to the login.php but i cant understand why isnt it working.

In the rendered source code I can see because the redirection is not occurring is ( The redirection code exists )

<script  type='text/javascript'> window.top.location='http://www.example.com/mobile/login.php'</script>
<!DOCTYPE html> 
<html> 
<head>...
.
.
.</html>

I am using Chrome and this is source code from where I am logging to mysettings.php page

<?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>
4

3 回答 3

2

您可以使用headerPHP 函数执行重定向:

<?php
    if(!isset($_SESSION['access_token'])) {
        header("Location: http://www.example.com/mobile/login.php");
        exit;
    }
?>

请注意,这需要在发送任何 HTML 标记之前执行

于 2013-01-26T15:21:54.390 回答
0

也许尝试使用 phpheader("Location: http://some/url");或者也尝试使用window.location.href instaed of top 最后尝试将脚本而不是文档标记而不是之前(可能有效?...)

于 2013-01-26T15:24:00.293 回答
0

我添加了

data-ajax="false" 

打开按钮mysettings.php,它开始正常工作。谢谢

于 2013-01-26T15:59:15.767 回答