Session Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maximus

    Session Problems

    Lately, i installed WAMP server on my pc, and started coding as always.

    Today, I noticed that sessions started going weird.

    I declare a session in page1 for example, I echo it in page2 after a
    form submission ... al goes fine ... then click a link on page2 leading
    to page 3 ..... the session is no longer valid.

    echoing the session gives NULL


    What's wring? any help?
    I am using session_start() ; in all 3 pages.

  • Good Man

    #2
    Re: Session Problems

    "Maximus" <teddy.am@gmail .comwrote in news:1163869860 .838020.132370
    @k70g2000cwa.go oglegroups.com:
    Lately, i installed WAMP server on my pc, and started coding as always.
    >
    Today, I noticed that sessions started going weird.
    >
    I declare a session in page1 for example, I echo it in page2 after a
    form submission ... al goes fine ... then click a link on page2 leading
    to page 3 ..... the session is no longer valid.
    >
    echoing the session gives NULL
    >
    >
    What's wring? any help?
    I am using session_start() ; in all 3 pages.

    are you calling it properly, via $_SESSION['mysession']; and not just
    expecting $mysession to exist without that?

    Comment

    • Jerry Stuckle

      #3
      Re: Session Problems

      Maximus wrote:
      Lately, i installed WAMP server on my pc, and started coding as always.
      >
      Today, I noticed that sessions started going weird.
      >
      I declare a session in page1 for example, I echo it in page2 after a
      form submission ... al goes fine ... then click a link on page2 leading
      to page 3 ..... the session is no longer valid.
      >
      echoing the session gives NULL
      >
      >
      What's wring? any help?
      I am using session_start() ; in all 3 pages.
      >
      Are you calling session_start before ANYTHING is sent to the client?
      This can include any DOCTYPE, etc. statements, or even white space.

      What happens if you add the following two statements right at the
      beginning of your file (before the session_start() call)?

      error_reporting (E_ALL);
      ini_set("displa y_errors","1");


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Maximus

        #4
        Re: Session Problems

        The same script thats working fine online on link:
        http://www.tam-sms.com is not working on my wamp server locally.

        I think there's a problem with the php.ini file installed by WAMP5
        server.
        Jerry Stuckle wrote:
        Maximus wrote:
        Lately, i installed WAMP server on my pc, and started coding as always.

        Today, I noticed that sessions started going weird.

        I declare a session in page1 for example, I echo it in page2 after a
        form submission ... al goes fine ... then click a link on page2 leading
        to page 3 ..... the session is no longer valid.

        echoing the session gives NULL


        What's wring? any help?
        I am using session_start() ; in all 3 pages.
        >
        Are you calling session_start before ANYTHING is sent to the client?
        This can include any DOCTYPE, etc. statements, or even white space.
        >
        What happens if you add the following two statements right at the
        beginning of your file (before the session_start() call)?
        >
        error_reporting (E_ALL);
        ini_set("displa y_errors","1");
        >
        >
        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Jerry Stuckle

          #5
          Re: Session Problems

          Maximus wrote:
          The same script thats working fine online on link:
          http://www.tam-sms.com is not working on my wamp server locally.
          >
          I think there's a problem with the php.ini file installed by WAMP5
          server.
          Jerry Stuckle wrote:
          >
          >>Maximus wrote:
          >>
          >>>Lately, i installed WAMP server on my pc, and started coding as always.
          >>>
          >>>Today, I noticed that sessions started going weird.
          >>>
          >>>I declare a session in page1 for example, I echo it in page2 after a
          >>>form submission ... al goes fine ... then click a link on page2 leading
          >>>to page 3 ..... the session is no longer valid.
          >>>
          >>>echoing the session gives NULL
          >>>
          >>>
          >>>What's wring? any help?
          >>>I am using session_start() ; in all 3 pages.
          >>>
          >>
          >>Are you calling session_start before ANYTHING is sent to the client?
          >>This can include any DOCTYPE, etc. statements, or even white space.
          >>
          >>What happens if you add the following two statements right at the
          >>beginning of your file (before the session_start() call)?
          >>
          >>error_reporti ng(E_ALL);
          >>ini_set("disp lay_errors","1" );
          >>
          >>
          >>--
          >>============= =====
          >>Remove the "x" from my email address
          >>Jerry Stuckle
          >>JDS Computer Training Corp.
          >>jstucklex@att global.net
          >>============= =====
          >
          >
          If that were the case I wouldn't expect it to work at all.

          What happens if you do a

          echo "<pre>\n";
          print_r($_SESSI ON);
          echo "</pre>\n";

          And what happens if you use the code I sent you earlier?

          What's the actual failing code?

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Maximus

            #6
            Re: Session Problems

            Jerry, here's the code for the 3 pages ...


            INDEX.PHP
            -----------------

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
            />
            <title>Untitl ed Document</title>
            </head>

            <body>
            <form id="form1" name="form1" method="post" action="page1.p hp">
            <label>
            <input type="text" name="textfield " />
            </label>
            <p>
            <label>
            <input type="submit" name="Submit" value="Submit" />
            </label>
            </p>
            </form>
            </body>
            </html>

            --------------------------
            PAGE1.PHP
            --------------------------
            <?php

            session_start() ;

            $_SESSION['1'] = $_POST['textfield'];

            echo $_SESSION['1'];

            echo "<pre>\n";
            print_r($_SESSI ON);
            echo "</pre>\n";

            ?>

            <p>&nbsp;</p>
            <p><a href="page2.php ">page 2</a</p>

            -----------------------------
            PAGE2.PHP
            -----------------------------

            <?php

            session_start() ;

            $var = $_SESSION['1'];

            echo $var;

            echo "<pre>\n";
            print_r($_SESSI ON);
            echo "</pre>\n";

            ?>

            -----------------------------
            Page 2 doesn't show any sessions registered.
            Nothin at alll ....


            Jerry Stuckle wrote:
            Maximus wrote:
            The same script thats working fine online on link:
            http://www.tam-sms.com is not working on my wamp server locally.

            I think there's a problem with the php.ini file installed by WAMP5
            server.
            Jerry Stuckle wrote:
            >Maximus wrote:
            >
            >>Lately, i installed WAMP server on my pc, and started coding as always.
            >>
            >>Today, I noticed that sessions started going weird.
            >>
            >>I declare a session in page1 for example, I echo it in page2 after a
            >>form submission ... al goes fine ... then click a link on page2 leading
            >>to page 3 ..... the session is no longer valid.
            >>
            >>echoing the session gives NULL
            >>
            >>
            >>What's wring? any help?
            >>I am using session_start() ; in all 3 pages.
            >>
            >
            >Are you calling session_start before ANYTHING is sent to the client?
            >This can include any DOCTYPE, etc. statements, or even white space.
            >
            >What happens if you add the following two statements right at the
            >beginning of your file (before the session_start() call)?
            >
            >error_reportin g(E_ALL);
            >ini_set("displ ay_errors","1") ;
            >
            >
            >--
            >============== ====
            >Remove the "x" from my email address
            >Jerry Stuckle
            >JDS Computer Training Corp.
            >jstucklex@attg lobal.net
            >============== ====
            >
            If that were the case I wouldn't expect it to work at all.
            >
            What happens if you do a
            >
            echo "<pre>\n";
            print_r($_SESSI ON);
            echo "</pre>\n";
            >
            And what happens if you use the code I sent you earlier?
            >
            What's the actual failing code?
            >
            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Jerry Stuckle

              #7
              Re: Session Problems

              Maximus wrote:
              Jerry Stuckle wrote:
              >
              >>Maximus wrote:
              >>
              >>>The same script thats working fine online on link:
              >>>http://www.tam-sms.com is not working on my wamp server locally.
              >>>
              >>>I think there's a problem with the php.ini file installed by WAMP5
              >>>server.
              >>>Jerry Stuckle wrote:
              >>>
              >>>
              >>>>Maximus wrote:
              >>>>
              >>>>
              >>>>>Lately, i installed WAMP server on my pc, and started coding as always.
              >>>>>
              >>>>>Today, I noticed that sessions started going weird.
              >>>>>
              >>>>>I declare a session in page1 for example, I echo it in page2 after a
              >>>>>form submission ... al goes fine ... then click a link on page2 leading
              >>>>>to page 3 ..... the session is no longer valid.
              >>>>>
              >>>>>echoing the session gives NULL
              >>>>>
              >>>>>
              >>>>>What's wring? any help?
              >>>>>I am using session_start() ; in all 3 pages.
              >>>>>
              >>>>
              >>>>Are you calling session_start before ANYTHING is sent to the client?
              >>>>This can include any DOCTYPE, etc. statements, or even white space.
              >>>>
              >>>>What happens if you add the following two statements right at the
              >>>>beginning of your file (before the session_start() call)?
              >>>>
              >>>>error_repor ting(E_ALL);
              >>>>ini_set("di splay_errors"," 1");
              >>>>
              >>>>
              >>>>--
              >>>>=========== =======
              >>>>Remove the "x" from my email address
              >>>>Jerry Stuckle
              >>>>JDS Computer Training Corp.
              >>>>jstucklex@a ttglobal.net
              >>>>=========== =======
              >>>
              >>>
              >>If that were the case I wouldn't expect it to work at all.
              >>
              >>What happens if you do a
              >>
              >>echo "<pre>\n";
              >>print_r($_SES SION);
              >>echo "</pre>\n";
              >>
              >>And what happens if you use the code I sent you earlier?
              >>
              >>What's the actual failing code?
              >>
              >>--
              >>============= =====
              >>Remove the "x" from my email address
              >>Jerry Stuckle
              >>JDS Computer Training Corp.
              >>jstucklex@att global.net
              >>============= =====
              >
              >
              Jerry, here's the code for the 3 pages ...
              >
              >
              INDEX.PHP
              -----------------
              >
              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
              />
              <title>Untitl ed Document</title>
              </head>
              >
              <body>
              <form id="form1" name="form1" method="post" action="page1.p hp">
              <label>
              <input type="text" name="textfield " />
              </label>
              <p>
              <label>
              <input type="submit" name="Submit" value="Submit" />
              </label>
              </p>
              </form>
              </body>
              </html>
              >
              --------------------------
              PAGE1.PHP
              --------------------------
              <?php
              >
              session_start() ;
              >
              $_SESSION['1'] = $_POST['textfield'];
              >
              echo $_SESSION['1'];
              >
              echo "<pre>\n";
              print_r($_SESSI ON);
              echo "</pre>\n";
              >
              ?>
              >
              <p>&nbsp;</p>
              <p><a href="page2.php ">page 2</a</p>
              >
              -----------------------------
              PAGE2.PHP
              -----------------------------
              >
              <?php
              >
              session_start() ;
              >
              $var = $_SESSION['1'];
              >
              echo $var;
              >
              echo "<pre>\n";
              print_r($_SESSI ON);
              echo "</pre>\n";
              >
              ?>
              >
              -----------------------------
              Page 2 doesn't show any sessions registered.
              Nothin at alll ....
              >
              >
              (Top posting fixed)

              OK, are you sure there is NOTHING before the <?php in page2.php?

              And what happens if you put the code I gave you immediately following
              the <?php tag?

              P.S. Please don't top post. Thanks.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Maximus

                #8
                Re: Session Problems

                There's nothing before the <?php

                and if i put the tag u gave me i get this

                Array
                (
                )



                This is the weirdest thing i ever got in PHP so far...

                Comment

                • Jerry Stuckle

                  #9
                  Re: Session Problems

                  Maximus wrote:
                  There's nothing before the <?php
                  >
                  and if i put the tag u gave me i get this
                  >
                  Array
                  (
                  )
                  >
                  >
                  >
                  This is the weirdest thing i ever got in PHP so far...
                  >
                  Sorry, this was the code I was referring to. I didn't mean to be confusing:


                  error_reporting (E_ALL);
                  ini_set("displa y_errors","1");

                  P.S. ensure you look at your page source, also.

                  One other thing - what does phpinfo() say for your session-related
                  settings? Your code should be working fine.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Jim Carlock

                    #10
                    Re: Session Problems

                    "Maximus" <teddy.am@gmail .composted:
                    : here's the code ...

                    Try the following...
                    <snip>
                    PAGE1.PHP...
                    <?php

                    session_start() ;

                    $_SESSION['1'] = $_POST['textfield'];

                    echo("<html>\n< head>\n<title>T est</title>\n</head>\n<body>\n ");
                    echo("<p>$_SESS ION['1']</p>\n");

                    echo "<pre>\n";
                    print_r($_SESSI ON);
                    echo "</pre>\n";

                    ?>

                    <p>&nbsp;</p>
                    <p><a href="page2.php ">page 2</a</p>
                    </body></html>
                    </snip>

                    Where's the <!DOCTYPE ... >, <html>, <headand <body>
                    tags? And do you have your cookies turned on in your browser?

                    --
                    Jim Carlock


                    Comment

                    • Maximus

                      #11
                      Re: Session Problems

                      PAGE1.PHPis working fine ...
                      PAGE2.PHP doesn't echo any sessions.

                      Sessions at that page turn to NULL.


                      Jim Carlock wrote:
                      "Maximus" <teddy.am@gmail .composted:
                      : here's the code ...
                      >
                      Try the following...
                      <snip>
                      PAGE1.PHP...
                      <?php
                      >
                      session_start() ;
                      >
                      $_SESSION['1'] = $_POST['textfield'];
                      >
                      echo("<html>\n< head>\n<title>T est</title>\n</head>\n<body>\n ");
                      echo("<p>$_SESS ION['1']</p>\n");
                      >
                      echo "<pre>\n";
                      print_r($_SESSI ON);
                      echo "</pre>\n";
                      >
                      ?>
                      >
                      <p>&nbsp;</p>
                      <p><a href="page2.php ">page 2</a</p>
                      </body></html>
                      </snip>
                      >
                      Where's the <!DOCTYPE ... >, <html>, <headand <body>
                      tags? And do you have your cookies turned on in your browser?
                      >
                      --
                      Jim Carlock

                      Comment

                      • Maximus

                        #12
                        Re: Session Problems

                        Now here's something even more weird

                        <?
                        phpinfo();
                        ?>

                        gives a blank white page ...


                        Jim Carlock wrote:
                        "Maximus" <teddy.am@gmail .composted:
                        : here's the code ...
                        >
                        Try the following...
                        <snip>
                        PAGE1.PHP...
                        <?php
                        >
                        session_start() ;
                        >
                        $_SESSION['1'] = $_POST['textfield'];
                        >
                        echo("<html>\n< head>\n<title>T est</title>\n</head>\n<body>\n ");
                        echo("<p>$_SESS ION['1']</p>\n");
                        >
                        echo "<pre>\n";
                        print_r($_SESSI ON);
                        echo "</pre>\n";
                        >
                        ?>
                        >
                        <p>&nbsp;</p>
                        <p><a href="page2.php ">page 2</a</p>
                        </body></html>
                        </snip>
                        >
                        Where's the <!DOCTYPE ... >, <html>, <headand <body>
                        tags? And do you have your cookies turned on in your browser?
                        >
                        --
                        Jim Carlock

                        Comment

                        • Erwin Moller

                          #13
                          Re: Session Problems

                          Maximus wrote:
                          Now here's something even more weird
                          >
                          <?
                          phpinfo();
                          ?>
                          >
                          Hi

                          Try:
                          <?php
                          phpinfo();
                          ?>


                          Maybe you didn't enable short open tags on your server.
                          (Check this by viewing the source from that page, it would read excactly:
                          <?
                          phpinfo();
                          ?>
                          which displays nothing in a browser, since it looks just like an (unknown)
                          tag.

                          Regards,
                          Erwin Moller

                          Comment

                          Working...