Question on Session

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alucard001@gmail.com

    #1

    Question on Session

    Hi all!

    I am a newbie in PHP and I have a question on using $_SESSION.

    To keep it short, here is the code:

    A.php:
    <?php
    if($_POST['username'] == 'USER' && $_POST['password'] == 'PWD'){
    $_SESSION['isLogin'] = 1;
    ?>
    <script language="javas cript">
    window.location .href="B.php";
    </script>
    <?php
    }
    ?>

    B.php:
    <?php
    print $_SESSION['isLogin'];
    ?>

    Assume username and password is correct, but B.php show NOTHING!!!
    That is, the $_SESSION haven't passed the value from one page to the
    other page...

    In php.ini: register_global s = On

    My question is: how to pass the value from one page to another, without
    using $_POST or some other things?

    Thanks in advance.

  • Marcus

    #2
    Re: Question on Session

    alucard001@gmai l.com wrote:[color=blue]
    > Hi all!
    >
    > I am a newbie in PHP and I have a question on using $_SESSION.
    >
    > To keep it short, here is the code:
    >
    > A.php:
    > <?php
    > if($_POST['username'] == 'USER' && $_POST['password'] == 'PWD'){
    > $_SESSION['isLogin'] = 1;
    > ?>
    > <script language="javas cript">
    > window.location .href="B.php";
    > </script>
    > <?php
    > }
    > ?>
    >
    > B.php:
    > <?php
    > print $_SESSION['isLogin'];
    > ?>
    >
    > Assume username and password is correct, but B.php show NOTHING!!!
    > That is, the $_SESSION haven't passed the value from one page to the
    > other page...
    >
    > In php.ini: register_global s = On
    >
    > My question is: how to pass the value from one page to another, without
    > using $_POST or some other things?
    >
    > Thanks in advance.
    >[/color]

    You need to call session_start() at the top of both scripts.

    Comment

    • Marcus

      #3
      Re: Question on Session

      alucard001@gmai l.com wrote:[color=blue]
      > Hi all!
      >
      > I am a newbie in PHP and I have a question on using $_SESSION.
      >
      > To keep it short, here is the code:
      >
      > A.php:
      > <?php
      > if($_POST['username'] == 'USER' && $_POST['password'] == 'PWD'){
      > $_SESSION['isLogin'] = 1;
      > ?>
      > <script language="javas cript">
      > window.location .href="B.php";
      > </script>
      > <?php
      > }
      > ?>
      >
      > B.php:
      > <?php
      > print $_SESSION['isLogin'];
      > ?>
      >
      > Assume username and password is correct, but B.php show NOTHING!!!
      > That is, the $_SESSION haven't passed the value from one page to the
      > other page...
      >
      > In php.ini: register_global s = On
      >
      > My question is: how to pass the value from one page to another, without
      > using $_POST or some other things?
      >
      > Thanks in advance.
      >[/color]

      Also, in your code you are using the $_POST and $_SESSION arrays, which
      is how you should access these variables with register_global s being
      off. Why not turn it off and make your system more secure?

      Comment

      • Alucard

        #4
        Re: Question on Session

        Thanks!

        I change my php.ini in the following way:

        session.auto_st art = 1

        And follow your comment:

        register_global s = Off

        Thanks for your support!!!

        Comment

        Working...