Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. problem with session varaibles

problem with session varaibles

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phphelpquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MacRaider4
    wrote on last edited by
    #1

    What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have <td><input name="myusername" type="text" id="myusername" style="width:150px"></td> on the first form to get the value and then session_register("myusername"); on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))

    <?php
    // Check if session is not registered , redirect back to main page.
    // Put this code in first line of web page.
    session_start();
    if (!session_is_registered(myusername)) {
    header("location:login.php");
    }
    ?>
    Test
    <?php
    $test = $_SESSION["myusername"];
    echo $test;
    ?>

    On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...

    L M T 3 Replies Last reply
    0
    • M MacRaider4

      What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have <td><input name="myusername" type="text" id="myusername" style="width:150px"></td> on the first form to get the value and then session_register("myusername"); on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))

      <?php
      // Check if session is not registered , redirect back to main page.
      // Put this code in first line of web page.
      session_start();
      if (!session_is_registered(myusername)) {
      header("location:login.php");
      }
      ?>
      Test
      <?php
      $test = $_SESSION["myusername"];
      echo $test;
      ?>

      On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Which version of PHP are you using?

      M 1 Reply Last reply
      0
      • M MacRaider4

        What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have <td><input name="myusername" type="text" id="myusername" style="width:150px"></td> on the first form to get the value and then session_register("myusername"); on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))

        <?php
        // Check if session is not registered , redirect back to main page.
        // Put this code in first line of web page.
        session_start();
        if (!session_is_registered(myusername)) {
        header("location:login.php");
        }
        ?>
        Test
        <?php
        $test = $_SESSION["myusername"];
        echo $test;
        ?>

        On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...

        M Offline
        M Offline
        MacRaider4
        wrote on last edited by
        #3

        I figured out my problem... as usual forgot the most simple aspect of programming :wtf: $_SESSION['myusername'] = $myusername; I really does help to actually assign a value to something... Hopefully this will help someone else that finds them self in the same lack of sleep state.

        1 Reply Last reply
        0
        • L Lost User

          Which version of PHP are you using?

          M Offline
          M Offline
          MacRaider4
          wrote on last edited by
          #4

          5.1.6 However stupid here realized that he forgot to actually assign the session variable a value. I guess the important thing is I figured it out :laugh:

          L 1 Reply Last reply
          0
          • M MacRaider4

            5.1.6 However stupid here realized that he forgot to actually assign the session variable a value. I guess the important thing is I figured it out :laugh:

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Since php version 5.3 don't forget that "session_register" has been deprecated and removed for version 6.0 so be caution of this gotcha!

            M 1 Reply Last reply
            0
            • L Lost User

              Since php version 5.3 don't forget that "session_register" has been deprecated and removed for version 6.0 so be caution of this gotcha!

              M Offline
              M Offline
              MacRaider4
              wrote on last edited by
              #6

              Thanks for the FYI, I'll account for it now before I forget about it.

              1 Reply Last reply
              0
              • M MacRaider4

                What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have <td><input name="myusername" type="text" id="myusername" style="width:150px"></td> on the first form to get the value and then session_register("myusername"); on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))

                <?php
                // Check if session is not registered , redirect back to main page.
                // Put this code in first line of web page.
                session_start();
                if (!session_is_registered(myusername)) {
                header("location:login.php");
                }
                ?>
                Test
                <?php
                $test = $_SESSION["myusername"];
                echo $test;
                ?>

                On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...

                T Offline
                T Offline
                Thomas D Williams
                wrote on last edited by
                #7

                Even though you seem to have found a solution, I have actually found some web hosting to be quite a pain if you are using Sessions. Depends on the provider though. With my current provider it was becoming way to complicated to set up properly so I used another method

                Thomas Williams - Chimp Twist

                M 1 Reply Last reply
                0
                • T Thomas D Williams

                  Even though you seem to have found a solution, I have actually found some web hosting to be quite a pain if you are using Sessions. Depends on the provider though. With my current provider it was becoming way to complicated to set up properly so I used another method

                  Thomas Williams - Chimp Twist

                  M Offline
                  M Offline
                  MacRaider4
                  wrote on last edited by
                  #8

                  This is just for a small intranet site. I think the most users I've ever had on at one time is 5 :) However I'm always looking for ideas.

                  T 1 Reply Last reply
                  0
                  • M MacRaider4

                    This is just for a small intranet site. I think the most users I've ever had on at one time is 5 :) However I'm always looking for ideas.

                    T Offline
                    T Offline
                    Thomas D Williams
                    wrote on last edited by
                    #9

                    Good luck with intranet site :)hope you don't find too many more issues. On my website in the end I reverted to cookies. When the user logs in it stores the information they typed in the form in 2 cookies (nom). Then every time any page loads I check it against the database, thus maintaining some form of security :)

                    Thomas Williams - Chimp Twist

                    M 1 Reply Last reply
                    0
                    • T Thomas D Williams

                      Good luck with intranet site :)hope you don't find too many more issues. On my website in the end I reverted to cookies. When the user logs in it stores the information they typed in the form in 2 cookies (nom). Then every time any page loads I check it against the database, thus maintaining some form of security :)

                      Thomas Williams - Chimp Twist

                      M Offline
                      M Offline
                      MacRaider4
                      wrote on last edited by
                      #10

                      I was having a heck of a time with cookies in a terminal services environment. Not really sure why that made a difference, but maybe I'll look back into that again in the future.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups