trouble with PHP session - i think ????

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

    trouble with PHP session - i think ????

    Hello i am not PHP expert - i need help big time.

    i am having issue with PHP session i think. I have two page login.php
    and admn.php As name implied login to log in to admin page manage
    database. But as soon as session initiated and passed to admin.php -
    the session variable fails and it always default to else section in
    php. And again - that what i think i may be completely off base.

    Here is the part of the code:

    login.php
    <?

    session_start() ;
    $expiry = 60*60; //1hr in seconds
    setcookie(sessi on_name(), session_id(), time()+$expiry, "/");
    ?>



    .....
    .....
    .....
    else //FORM SUBMITTED
    {
    include ("config.php ");
    //validate username and pass
    $user_name = $HTTP_POST_VARS['username'];
    $pass_word = $HTTP_POST_VARS['pass'];

    $connection = mysql_connect($ host, $user, $pass) or die ("Unable to
    connect!");
    mysql_select_db ($db) or die (mysql_error()) ;
    $query = "SELECT * FROM ".$users_table. " WHERE username =
    '$user_name' AND password = '$pass_word'";
    $result = mysql_query($qu ery) or die (mysql_error()) ;

    if (mysql_num_rows ($result) == 1)
    {
    //valid pass


    $row = mysql_fetch_obj ect($result);
    if (!empty($row))
    {
    //session_unregis ter( "USER" );
    session_registe r( "db_user", "db_cat", "db_usernam e",
    "db_name" );


    $db_name = $row->first_name." ".$row->last_name;
    $db_username = $row->username;
    $db_user = md5($db_usernam e);
    $db_cat = $row->category;

    echo "<div style='text-align: center; font-family: verdana; font-
    size: 13px'><b>Log-in Successful.</b>

    <br>Remember to log-off when finished.<br><b r>Redirecting to <a
    href='admin.php '>Admin Page</a>...</div>";
    echo "<meta http-equiv=\"refresh \" content=\"1;URL =admin.php\">";
    }




    Admin.php
    <?session_save_ path("/tmp");
    session_start() ;?>

    <?

    if ( isset ($db_cat))
    {?>
    <?}
    else
    echo "<meta http-equiv=\"refresh \" content=\"1;URL =login.php\">"; ?>

  • #2pencil

    #2
    Re: trouble with PHP session - i think ????

    login.php
    <?


    session_start() ;
    $expiry = 60*60; //1hr in seconds
    setcookie(sessi on_name(), session_id(), time()+$expiry, "/");
    ?>


    .....
    .....
    .....
    else //FORM SUBMITTED

    It looks as if you close your php code block & then never start it
    again. Was this part not pasted, or is this how your code actually
    reads? Also, you should start your php code block with <?php rather
    than just <?.

    -#2pencil-
    Computer Design and Repair. Providing Nintendo 3DS, Apple iPad/iPhone, Laptop, PC, and Web Development/SEO/Hosting services.


    Comment

    • SA SA

      #3
      Re: trouble with PHP session - i think ????

      On Jul 12, 3:10 pm, #2pencil <number2pen...@ gmail.comwrote:
      login.php
      <?
      >
      session_start() ;
      $expiry = 60*60; //1hr in seconds
      setcookie(sessi on_name(), session_id(), time()+$expiry, "/");
      ?>
      >
      ....
      ....
      ....
      else //FORM SUBMITTED
      >
      It looks as if you close your php code block & then never start it
      again. Was this part not pasted, or is this how your code actually
      reads? Also, you should start your php code block with <?php rather
      than just <?.
      >
      -#2pencil-http://www.akroncdnr.c om
      Thanks
      I added <?PHP but did not make difference. As for as code block. I
      just did not copied all code - just portion. It is open and closed and
      open properly.

      It worked in the past - i am having this issue ever since hosting
      company moved me to different server.

      thanks
      sa

      Comment

      • Good Man

        #4
        Re: trouble with PHP session - i think ????

        SA SA <suacharya@gmai l.comwrote in news:1184270422 .153910.291110
        @r34g2000hsd.go oglegroups.com:

        I added <?PHP but did not make difference. As for as code block. I
        just did not copied all code - just portion. It is open and closed and
        open properly.
        it should be <?php (not <?PHP ) and it wasn't suggested for making a
        difference with your problem, but to make sure your code runs in the
        future, regardless of web host.

        It worked in the past - i am having this issue ever since hosting
        company moved me to different server.
        maybe this is your problem then (from your code):
        session_save_pa th("/tmp");

        Perhaps the path "/tmp" doesn't exist, or it doesn't have the proper
        permissions that let you write a file there.

        Comment

        • SA SA

          #5
          Re: trouble with PHP session - i think ????

          On Jul 12, 4:53 pm, Good Man <h...@letsgo.co mwrote:
          SA SA <suacha...@gmai l.comwrote in news:1184270422 .153910.291110
          @r34g2000hsd.go oglegroups.com:
          >
          I added <?PHP but did not make difference. As for as code block. I
          just did not copied all code - just portion. It is open and closed and
          open properly.
          >
          it should be <?php (not <?PHP ) and it wasn't suggested for making a
          difference with your problem, but to make sure your code runs in the
          future, regardless of web host.
          >
          It worked in the past - i am having this issue ever since hosting
          company moved me to different server.
          >
          maybe this is your problem then (from your code):
          session_save_pa th("/tmp");
          >
          Perhaps the path "/tmp" doesn't exist, or it doesn't have the proper
          permissions that let you write a file there.
          To check to see if the /tmp folder exits i tested the code with fake
          folder /1ggh00 name. Sure enough it gave me folder not found error.
          Seems like folder does exits, but not sure if i have write permission
          to it.



          One intersting thing - time to time i see this message not sure if it
          is related.

          "Warning: Unknown():Your script possibly relies on session side-effect
          which existed until PHP 4.2.3 please be advised that the session
          extension does not consider gloabl variables as source of data unless
          register_global s is enabled. You can disable this funcationality and
          this warning by setting session.bug_com pt_42 or session.bug_com pt_warn
          to off, respectively. in unknown in line 0"

          Comment

          • Good Man

            #6
            Re: trouble with PHP session - i think ????

            SA SA <suacharya@gmai l.comwrote in news:1184276300 .871187.258560
            @n2g2000hse.goo glegroups.com:
            It worked in the past - i am having this issue ever since hosting
            company moved me to different server.
            >>
            >maybe this is your problem then (from your code):
            >session_save_p ath("/tmp");
            >>
            >Perhaps the path "/tmp" doesn't exist, or it doesn't have the proper
            >permissions that let you write a file there.
            >
            To check to see if the /tmp folder exits i tested the code with fake
            folder /1ggh00 name. Sure enough it gave me folder not found error.
            Seems like folder does exits, but not sure if i have write permission
            to it.
            One thing is almost for certain... you do not have permission to write
            to any folder at the top of the computer ("/1ggh00") on a shared web
            host. You can probably create and write to "1ggh00/" though (ie: a
            directory UNDER your user/website).

            I also gotta say that I use sessions extensively, and I do so without
            explicitly using cookies or writing to any file. It's just

            $_SESSION['MySessionName'] = 'yeehah!';

            to set, and

            $thesession = $_SESSION['MySessionName'];

            to put the read the session value and put it into the variable
            "$thesessio n".

            Not sure why you're jumping through hoops, (ie: trying to specify where
            the session info is stored) but maybe I need to read your post again.

            One intersting thing - time to time i see this message not sure if it
            is related.
            >
            "Warning: Unknown():Your script possibly relies on session side-effect
            which existed until PHP 4.2.3 please be advised that the session
            extension does not consider gloabl variables as source of data unless
            register_global s is enabled. You can disable this funcationality and
            this warning by setting session.bug_com pt_42 or session.bug_com pt_warn
            to off, respectively. in unknown in line 0"
            freaky, i imagine there's some Google info on this somewhere....



            Comment

            • Good Man

              #7
              Re: trouble with PHP session - i think ????

              Good Man <heyho@letsgo.c omwrote in news:Xns996BB5F E659EAsonicyout h@
              216.196.97.131:

              furthermore, if you look at the manual page for "session_regist er()" (which
              you are using in your code):



              There are warnings abound. Of particular importance is the following:

              // Use of session_registe r() is deprecated
              $barney = "A big purple dinosaur.";
              session_registe r("barney");

              // Use of $_SESSION is preferred, as of PHP 4.1.0
              $_SESSION["zim"] = "An invader from another planet


              So drop the deprecated usage, stop trying to re-invent the wheel unless you
              have a valid reason for doing so, and use sessions as they were meant to be
              used - quickly and EASILY via my previous example.

              Good luck.

              Comment

              • SA SA

                #8
                Re: trouble with PHP session - i think ????

                On Jul 12, 5:57 pm, Good Man <he...@letsgo.c omwrote:
                Good Man <he...@letsgo.c omwrote in news:Xns996BB5F E659EAsonicyout h@
                216.196.97.131:
                >
                furthermore, if you look at the manual page for "session_regist er()" (which
                you are using in your code):
                >

                >
                There are warnings abound. Of particular importance is the following:
                >
                // Use of session_registe r() is deprecated
                $barney = "A big purple dinosaur.";
                session_registe r("barney");
                >
                // Use of $_SESSION is preferred, as of PHP 4.1.0
                $_SESSION["zim"] = "An invader from another planet
                >
                So drop the deprecated usage, stop trying to re-invent the wheel unless you
                have a valid reason for doing so, and use sessions as they were meant to be
                used - quickly and EASILY via my previous example.
                >
                Good luck.
                I will attempt to make changes per your suggestion. Thanks

                Comment

                • Toby A Inkster

                  #9
                  Re: trouble with PHP session - i think ????

                  SA SA wrote:
                  setcookie(sessi on_name(), session_id(), time()+$expiry, "/");
                  Don't do this. Use the session.cookie_ lifetime setting instead.

                  --
                  Toby A Inkster BSc (Hons) ARCS
                  [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
                  [OS: Linux 2.6.12-12mdksmp, up 22 days, 11:35.]

                  demiblog 0.2.0 Released

                  Comment

                  • Markus

                    #10
                    Re: trouble with PHP session - i think ????

                    SA SA schrieb:
                    Hello i am not PHP expert - i need help big time.
                    >
                    i am having issue with PHP session i think. I have two page login.php
                    and admn.php As name implied login to log in to admin page manage
                    database. But as soon as session initiated and passed to admin.php -
                    the session variable fails and it always default to else section in
                    php. And again - that what i think i may be completely off base.
                    In addition to what has been written already by others, I see:
                    login.php
                    <?
                    >
                    session_start() ;
                    And:
                    Admin.php
                    <?session_save_ path("/tmp");
                    session_start() ;?>
                    It looks like you store the session in different locations in login.php
                    and Admin.php. So possibly Admin.php starts a new session in /tmp, even
                    if login.php has started one already in another directory which is
                    default for your server.

                    HTH
                    Markus

                    Comment

                    Working...