24 Replies Latest reply on Apr 16, 2008 9:02 PM by (shane_mosier)

    NEED HELP!!!!!    Session Variables not being passed

    Level 1
      Just like everybody i am very new to this. When i add a session variable to the page nothing shows up. From what i have researched, the login session variables kt_login_id is not being passed. I have heard people talking about writing a php.ini file, but i have now idea how to get mine from the server to be able to change it, or what even to do with it.

      Things i have done already:

      -Added to Line 1 in all the pages that i need the variables and the login page.

      -Made sure that require_once('../../includes/tng/tNG.inc.php'); is on the page also.

      Here are my PhpInfo Page settings for session

      Session Support enabled
      Registered save handlers files user

      Directive Local Value Master Value
      session.auto_start Off Off
      session.bug_compat_42 On On
      session.bug_compat_warn On On
      session.cache_expire 180 180
      session.cache_limiter nocache nocache
      session.cookie_domain no value no value
      session.cookie_lifetime 0 0
      session.cookie_path / /
      session.cookie_secure Off Off
      session.entropy_file no value no value
      session.entropy_length 0 0
      session.gc_divisor 100 100
      session.gc_maxlifetime 1440 1440
      session.gc_probability 1 1
      session.name PHPSESSID PHPSESSID
      session.referer_check no value no value
      session.save_handler files files
      session.save_path .\ .\
      session.serialize_handler php php
      session.use_cookies On On
      session.use_only_cookies Off Off
      session.use_trans_sid Off Off

      in fact you can go here to look www.portersrestoration.com/test.php

      I have set-up an error message for the page that the session kt_login_id should be passed and this is what it says

      Notice: Undefined index: kt_login_id in C:\hshome\webtech\portersrestoration.com\portersonline\private\index.php on line 73

      PLEASE HELP!!!

      Thanks in advance
        • 1. Re: NEED HELP!!!!!    Session Variables not being passed
          Waleed Barakat Level 1
          Hello Joe A Porter
          to get your session varibale working well your page should be "restricted" this means:
          If your page is a non puplic one let`s say: "user account" or other restricted areas it should be restricted.

          ================================
          and as you said or others said:
          I have heard people talking about writing a php.ini file
          ================================

          all of this is just thought but to have your _SESSION VARIABLE working please follow:

          -----------------------------
          - open your page in dreamweaver and go to > server behavior panel > developer toolbox > user login > Restrict access to page


          and try to pass your login variable "$_SESSION['kt_login_id']" and it will work so fine...
          • 2. Re: NEED HELP!!!!!    Session Variables not being passed
            Level 1
            Restricting the page to a specific user doesnt work because the it doesnt pass any of the permission session variables either. <br /> <br />I have another post regarding this too, http://www.adobeforums.com/webx/.59b4f948/0 <br /> <br />But after i posted that i realized that it is a session problem and not a permission. <br /> <br />Here is my page code that should have the variables passed to <br /> <br /><?php require_once('../../Connections/portersonline.php'); ?> <br /><?php<br /><br />// Load the common classes<br />require_once('../../includes/common/KT_common.php');<br /> <br /><br />// Load the tNG classes<br />require_once('../../includes/tng/tNG.inc.php');<br /><br />// Make unified connection variable<br />$conn_portersonline = new KT_connection($portersonline, $database_portersonline);<br /><br />//Start Restrict Access To Page<br />$restrict = new tNG_RestrictAccess($conn_portersonline, "../../");<br />//Grand Levels: Any<br />$restrict->Execute();<br />//End Restrict Access To Page<br /><br />// Make a transaction dispatcher instance<br />$tNGs = new tNG_dispatcher("../../");<br />?> <br /> <br /><?php<br /><br />if (!function_exists("GetSQLValueString")) {<br />function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") <br />{<br />  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;<br /><br />  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);<br /><br />  switch ($theType) {<br />    case "text":<br />      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";<br />      break;    <br />    case "long":<br />    case "int":<br />      $theValue = ($theValue != "") ? intval($theValue) : "NULL";<br />      break;<br />    case "double":<br />      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";<br />      break;<br />    case "date":<br />      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";<br />      break;<br />    case "defined":<br />      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;<br />      break;<br />  }<br />  return $theValue;<br />}<br />}<br /><br />$colname_rsEm = "-1";<br />if (isset($_SESSION['kt_login_id'])) {<br />  $colname_rsEm = $_SESSION['kt_login_id'];<br />}<br />mysql_select_db($database_portersonline, $portersonline);<br />$query_rsEm = sprintf("SELECT * FROM tblEmployee WHERE EmployeeID = %s", GetSQLValueString($colname_rsEm, "int"));<br />$rsEm = mysql_query($query_rsEm, $portersonline) or die(mysql_error());<br />$row_rsEm = mysql_fetch_assoc($rsEm);<br />$totalRows_rsEm = mysql_num_rows($rsEm);<br />?> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /><?php echo $row_rsEm['Em_FName']; ?> <br /><?php echo $_SESSION['kt_login_id']; ?> <br /> <br /> <br /><?php<br />mysql_free_result($rsEm);<br />?>
            • 5. Re: NEED HELP!!!!!    Session Variables not being passed
              Günter Schenk Level 4
              Hi Joe,

              sorry man, we apparently all enjoyed the weekend :-)

              Your session values look alright, but I wonder about...

              session.save_path .\ .\

              Is this one not defined at all ? Usually you need to make sure this directive points to an existing directory, like "/tmp" (on linux) or C:\tmp (on windows) -- however, if session.save_path isn´t set or hasn´t been correctly defined, you´ll run into such problems, as the sessions are not getting saved on the server.

              -----
              but i have now idea how to get mine from the server to be able to change it
              -----

              if that happens with your remote web host, they will have to look at that and fix possible errors - there´s nothing you can do.

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 6. Re: NEED HELP!!!!!    Session Variables not being passed
                Level 1
                Thanks for helping gunter.

                I will try to get in touch with the hosting company. I think they are getting stored because if i look at the remote server in the private folder and the admin folders i have set up and there are a bunch of files like...sess_4adf4wsag6e8090. Are these the session variable getting stored. Are they suppose to be in one area and not scattered through different folders.

                What do you think

                THANKS!!!
                • 7. Re: NEED HELP!!!!!    Session Variables not being passed
                  Level 1
                  try ' session_start(); ' at the start of your script
                  • 8. Re: NEED HELP!!!!!    Session Variables not being passed
                    Level 1
                    I got the mail back from the hosting company and this is what they told me <br /> <br />"If you are encountering issues with passing sessions from page to page and folder to folder it is possible you are encountering a known issue with PHP, information on which can be found at http://us2.php.net/session_start. That information should allow you to devise a workaround for this. <br /> <br />Please let us know if you need anything else, and have a good day." <br /> <br />This is what i have at the top of the login in page and the top of the second page in another folder that the login page is redirecting based on the user permission level: <br /> <br /><?php<br />error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);<br />session_start();<br />ob_start();<br />?> <br /> <br />This is the error on the second page: <br /> <br />Notice: Undefined index: kt_login_user <br /> <br />Do i need to set that variable at the top of each page two like <br /> <br />$_SESSION['favcolor'] = 'green' (just an example, i would need help on that what actually to call) <br /> <br />Thanks for the help guys
                    • 9. Re: NEED HELP!!!!!    Session Variables not being passed
                      Günter Schenk Level 4
                      Joe,

                      what PHP version is running on the remote host ?

                      Cheers,
                      Günter Schenk
                      Adobe Community Expert, Dreamweaver
                      • 11. Re: NEED HELP!!!!!    Session Variables not being passed
                        Level 1
                        another message from the hosting company:

                        There are no known issues with our servers which would cause PHP session issues, and other customers are using PHP sessions in our hosting without issue so no further settings should be necessary on our end to support your code to our knowledge. Please note that PHP session files are saved in the web root of the domain they are started on. If you will please reply back with specific step-by-step instructions for reproducing this issue we will be more than happy to investigate further.

                        but now if I look an the remote server there sess 5h7u(8(jjkh files scattered through out does that make a difference
                        • 13. Re: NEED HELP!!!!!    Session Variables not being passed
                          Level 1
                          Joe,

                          I think ,as Günter mentioned to on an earlier post, your problem lies in the following line of your php settings:

                          session.save_path .\ .\

                          which is related to the comment you got from tech support:

                          "Please note that PHP session files are saved in the web root of the domain they are started on."

                          My php setting(which is set in the php.ini file) for a linux box looks like this:

                          session.save_path /tmp

                          My php setting for a windows box looks like this:

                          session.save_path C:\WINDOWS\Temp

                          Your setting looks like it's for a windows box, but is a relative save path. I don't think it's a good idea for any hosting setup to write the sess 5h7u(8(jjkh files you see to the root directory, or have a relative save path such as .\.\ Doesn't really make sense to me, but I'm by no means a hosting expert.

                          Why shouldn't you write these files...read this from php.net site:

                          http://us.php.net/session

                          "Another gotcha to add to this list is that using a relative session.save_path is a VERY BAD idea.

                          You can just about pull it off, if you're very careful, but note two related points:

                          1) The path is taken relative to the directory of the ORIGINALLY executed script, so unless all pages are run from the same directory, you'll have to set the directory separately in each individual subfolder

                          2) If you call certain functions, such as session_regenerate_id(), PHP will try to take the session directory relative to the exectuable, or something like that, creating an error IN the executable. This provides slightly cryptic error messages, like this:

                          Warning: Unknown: open(relative_path\ilti9oq3j9ks0jvih1fmiq4sv1.session, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

                          Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (relative_path) in Unknown on line 0

                          ... so don't even bother. Just use



                          (or equivalent) in a file which you know is always in the same place relative to the file."

                          If you follow his advice at the end, you may be able to use that code to manually set the session.save_path. You might have to do this at the begining of each php page in which you need sessions to work. I've never needed to do this, so I can't vouch for it, but you might try:



                          at the top of your page. You may have to escape the forward slashes in C:\WINDOWS\Temp...not sure

                          Read the other posts on:

                          http://us.php.net/session

                          relating to the session.save_path...there seemed to be a lot of information.

                          One last note, make sure your php scripts have permission to write to the root directory of your site. I built a site for a customer that runs plesk on windows and the server admin upgraded plesk and my scripts were not able to read or write to the root directory. So it may be a permissions problem.

                          Hope this helps.

                          Shane
                          • 14. Re: NEED HELP!!!!!    Session Variables not being passed
                            Level 1
                            so to fix this i should put this

                            ?php ini_set("session.save_path",dirname(__FILE__)."C:\WINDOWS\Temp"); ?>

                            At the top of each page.

                            Sorry im a newbie
                            • 15. Re: NEED HELP!!!!!    Session Variables not being passed
                              Günter Schenk Level 4
                              Hi Shane,

                              wow, thanks, that´s an interesting information, didn´t know that !

                              Joe,

                              ----
                              so to fix this i should put this

                              ?php ini_set("session.save_path",dirname(__FILE__)."C:\WINDOWS\Temp"); ?>

                              At the top of each page
                              ----

                              I´m not convinced that *you* would have to apply such tedious workarounds for something which should rather be fixed by your host once and for all. I´ve also noticed that your website is running on a Windows system, what´s a bit unusual for web hosts which usually run their stuff on a Linux/Unix system.

                              However, even that shouldn´t be an issue though, as your website is otherwise running on an Apache server anyway, and all they´d have to do is to define a specified folder, like Shane suggested. And doing that shouldn´t be too hard, as it´s something us "localhost" developers always care for when setting up a PHP/Apache/MySQL environment on our Windows workstations, and it should just them 2 minutes to create that C:\WINDOWS\Temp folder and modify the php.ini accordingly.

                              You might have noticed that these forums contain lots of "my sessions don´t work" posts, and so far the provided solutions were always related to just two possible causes:

                              1) folks didn´t know they will have to add on line 1 for all manually created PHP documents, whereas this is not required with ADDT Dynamic Lists and Forms, as the session detection is built in right away

                              2) server configurations which are inaccurate or - like apparently in your case - based on some odd settings, and this should IMO be fixed by your host according to the "rules" rather than forcing you to add that ini_set("session.save_path... to all your pages. This might not even work, as some web hosts disable such "override default settings" workarounds, and then ?

                              Cheers,
                              Günter Schenk
                              Adobe Community Expert, Dreamweaver
                              • 16. Re: NEED HELP!!!!!    Session Variables not being passed
                                Level 1
                                AHHA this is so frustrating.

                                I made one final plea to the host and this is what they said.

                                "Read/write access for your account is limited to the FTP root of your account and its subfolders for security reasons, and we cannot make a change like this for that same reason. Many other customers are using PHP sessions in our hosting without issue, so you should be able to as well as long as your code is properly configured. Please note that our PHP version is PHP version 4.4, so if you are trying to use syntax from a different version of PHP that may be the cause of the issue."

                                Developer Toolbox works with 4.4 right???
                                • 17. Re: NEED HELP!!!!!    Session Variables not being passed
                                  Level 1
                                  Joe, <br /> <br />Code 2 pages like so and upload to your server. <br /> <br />file name: <br />test1.php <br /> <br />code: <br /><?php<br />session_start();<br />$_SESSION['test'] = "Session is Set";<br />echo "Step one completed...";<br />exit;<br />?> <br /> <br />file name: <br />test2.php <br /> <br />code: <br /><?php<br />session_start();<br />echo "Test Result: " . $_SESSION['test'];<br />exit;<br />?> <br /> <br />This is about the most vanilla test for SESSION variables. I tested this on one of my servers just to be sure the code is correct. <br /> <br />So upload both of those files and then run them in your browser by going to the url for those pages. <br /> <br />On the second page you will see: <br /> <br />Test Result: Session is Set <br /> <br />if the session is set. This will let you know if sessions are working at all, regardless of the Developer Toolbox. <br /> <br />If this does not work, you can at least point tech support to those pages so they can see that it's not working. That code is about as simple as you can get for using/testing session variables. <br /> <br />Shane
                                  • 18. Re: NEED HELP!!!!!    Session Variables not being passed
                                    Level 1
                                    Well i guess we have it somewhat down to the problem. It doesnt work from folder to folder.

                                    bare with the ip address (i switched to a dedicated ip so the dns servers havent propagated yet)

                                    Http://www.portersrestoration.com/portersonline/test1.php sets the session okay.

                                    Then go to: Http://www.portersrestoration.com/portersonline/test2.php seems to work fine.

                                    But now if you goto Http://www.portersrestoration.com/portersonline/private/test2.php
                                    the session doesnt carry over

                                    anything i can do to fix this.

                                    Thank you Shane for helping
                                    • 19. Re: NEED HELP!!!!!    Session Variables not being passed
                                      Level 1
                                      sorry corrected links

                                      http://67.19.231.46/portersonline/test1.php

                                      http://67.19.231.46/portersonline/test2.php

                                      http://67.19.231.46/portersonline/private/test2.php
                                      • 20. Re: NEED HELP!!!!!    Session Variables not being passed
                                        Level 1
                                        Joe,

                                        Not sure why this would not work on sub folders. Just to check, can you try running test1.php out of the private folder and then run the private/test2.php as well.

                                        Shane
                                        • 21. Re: NEED HELP!!!!!    Session Variables not being passed
                                          Level 1
                                          Works no problem with in the directory

                                          try

                                          http://67.19.231.46/portersonline/private/test1.php
                                          http://67.19.231.46/portersonline/private/test2.php
                                          • 22. Re: NEED HELP!!!!!    Session Variables not being passed
                                            Level 1
                                            Yep, i put the login page in the Private folder, then i logged in with a user of the private permission, it redirected to the index.php in the private folder and the sessions were passed. What do you think i can do to make it global through out the site. Because they are not being passed to sub folders or up in the folder list
                                            • 23. Re: NEED HELP!!!!!    Session Variables not being passed
                                              Level 1
                                              HOLY CRAP!!! I think i got. Now please tell me that this is completely okay and safe. Because at this point im fine with putting this at the top of every page.

                                              I have set session save path and call it on every page the same way and it works, here is what it looks like

                                              error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
                                              session_save_path("C:\A\bunch\directories\on\my\site");
                                              session_start();

                                              I have this on the login page and then all other files, even ones not in that directory, and the session gets passed.

                                              Is this safe and okay. I understand i have to do this on all used pages but at this point after 4 days of problems, im okay with.

                                              let me know your thoughts
                                              • 24. Re: NEED HELP!!!!!    Session Variables not being passed
                                                Level 1
                                                Joe,

                                                I think you should be fine, but that's not a personal guarantee :)

                                                As long as your hosting does not disable php's ability to override this setting, I think you will be fine.

                                                But I think the root cause of the problem is your hosting company's method of handling the session variable path with a \.\.

                                                Yeah they are right that session variables work on their servers, but only if you call scripts from the same directory? That does not see right to me.

                                                Anyways, glad your up and going. Now your an expert on SESSIONS no? :)

                                                Shane