如何使用会话在页面之间导航

时间:2018-07-11 06:50:06

标签: php

我们可以编写这样的代码来使这些代码真正起作用吗?

  if (JSON.parse(isLogin) == true) {
    Navigation.startSingleScreenApp({
      screen: {
        screen: "auxxa.LandingScreen",
        navigatorStyle: {
          navBarHidden: true
        }
      },
      appStyle: {
        keepStyleAcrossPush: false
      },
      portraitOnlyMode: true,
      overrideBackPress: true
    });
  } else {
    Navigation.startSingleScreenApp({
      screen: {
        screen: "auxxa.LoginScreen",
        navigatorStyle: {
          navBarHidden: true
        }
      },
      appStyle: {
        keepStyleAcrossPush: false
      },
      portraitOnlyMode: true,
      overrideBackPress: true
    });
  }

2 个答案:

答案 0 :(得分:1)

您是否提到代码不起作用? 您需要先使用session_start()来使脚本访问会话变量。

答案 1 :(得分:0)

您必须在每个页面的顶部添加session_start();。如果不是,则不能。

示例:

<?php 
    session_start();
    if (isset($_SESSION['u_id'])) {
        header("Location: profile.php");
    } 
    else {
        header("Location: index.php");
    }
?>