12 Replies Latest reply on Nov 8, 2007 8:31 AM by (Jim_Rol)

    edit session value after login

      I would like to edit the session value of a session that is set after a user logs in.

      Problem:
      I have a field 'date of birth' in my database: yyyy-mm-dd, but i need the age value instead in the session.

      I know how to calculate this but that is not the question, i need to know where to edit this value so that after a login the session is set to the age of the user instead of his/her date of birth value from the database.

      I hope you understand.
      Can someone please help me out...

      Thanks,
      Jim
        • 1. Re: edit session value after login
          Günter Schenk Level 4
          Hi Jim,

          I´d suggest changing the "date_of_birth" column to a numeric (int) one and create yourself an extra "admin only" update record list & form for changing this value.

          would that help ?

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: edit session value after login
            Level 1
            Thanks Günter for your fast reply!
            Well yes maybe that would help but I hope there is an easier solution to do this, because that needs unnecessary extra work and data in the database. (or did I misunderstood?)

            There must be a place in the login function where I can check the session value and if needed can change this to a format that is needed.

            I tried it on one or two places but that didn't work. I hope someone who is more experienced can help me find the right place to do this.

            Thanks anyway.
            Jim
            • 3. Re: edit session value after login
              Günter Schenk Level 4
              Hi Jim,

              -----
              There must be a place in the login function where I can check the session value and if needed can change this to a format that is needed
              -----

              this feature doesn´t exist, by default all login table data is getting displayed "as is" when used as session variable -- however I think it should be possible to perform an age calculation based on the user´s birthday and assign the result to a new PHP variable, which in turn can be assigned to a new session variable. I´ve seen similar stuff & tutorials on the web, so this should be possible.

              -----
              because that needs unnecessary extra work and data in the database
              -----

              sure, this would also "qualify" as redundant data -- an "on the fly" conversion is always the better way.

              What do you need this for -- just for display purposes, or will the user´s age eventually be inserted to some other table ?

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: edit session value after login
                Level 1
                Hello again Günter :)

                well yes that is exactly what i want to do. I just now need to find the right place in the login process code (fuctions) where the session is set and i can savely change the sessions value.

                I need the age value for my banner system. I give a few variables to the banner server to be able to show banners to the visitor that are for this group (age, sex, educationlevel, postcode).

                The postcode also needs some modification: in the database it can be the full code like '1234 AB' but the banner system only needs/wants the first 4 numbers.

                Hope that helps?
                • 5. Re: edit session value after login
                  Günter Schenk Level 4
                  Hi Jim, <br /> <br />please try with these sample scripts: <br /> <br /> <b>1. calculate age from birthday</b> <br /> <br /><?php<br />function birthday ($birthday)<br />{<br />list($year,$month,$day) = explode("-",$birthday);<br />$year_diff = date("Y") - $year;<br />$month_diff = date("m") - $month;<br />$day_diff = date("d") - $day;<br />if ($month_diff < 0) $year_diff--;<br />elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;<br />return $year_diff;<br />}<br />// original version : http://snipplr.com/view/1357/calculate-age/<br />?> <br /> <br /><?php<br />$birthday_user = '1961-12-31'; // can also be data from a query or session<br />$current_age = birthday($birthday_user); // use this variable to calculate<br />echo $current_age;  <br />?> <br /> <br /> <b>2. display the first 4 chars from a string</b> <br /> <br /><?php<br />$compare_against = '123456';<br />//$compare_against = $row_queryname['column_name'];<br />$new_postcode = substr($compare_against, 0, 4);<br />?> <br /> <br /><?php<br />echo $new_postcode;<br />?> <br /> <br />Cheers, <br />Günter Schenk <br />Adobe Community Expert, Dreamweaver
                  • 6. Re: edit session value after login
                    Günter Schenk Level 4
                    As the code in my previous reply is missing the line breaks, I´m attaching a text version.

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 7. Re: edit session value after login
                      Level 1
                      Hello Günter,

                      Thanks for your time and help with my problem!! Really appreciate that.

                      But somehow i just did not make myself clear:
                      I do not need functions to convert the values (I allready had these, altough yours look very intresting aswell!) but i need to find the right place where i can call these functions so that the sessions get these converted values upon logging in.

                      Do you understand what i need?

                      Hope to hear from you.
                      Bye, Jim
                      • 8. Re: edit session value after login
                        Level 1
                        Someone else maybe? ( Adobe, InterAkt...?)
                        • 9. Re: edit session value after login
                          Günter Schenk Level 4
                          Hi Jim, <br /> <br />nope, Adobe/Interakt are not participating here. <br /> <br />However, I do *think* that converting these values *upon* login seems quite weird to do -- ADDT´s session variables are based on the "as is" contents of DB table fields, and what you´re asking for is a very special usage scenario which was even never asked for in the Interakt forums, so that´s why assumingly other forum particpants reading this keep scratching their heads as well. <br /> <br />The only approach I can suggest for now, is to convert the session variables *after* login, and that´s quite easily possible -- on that very page that´s going to display the banner, it should be possible to initialize the abovementioned "calculate age from birthday" conversion routine and assign the session variable "current_age" to the PHP variable "$birthday_user", e.g. $birthday_user = $_SESSION['current_age']; <br /> <br />Once you have this clearly assigned, all you´d have to do is to apply a "Show IF conditional region" that´s checking against the $birthday_user value, e.g. <br /> <br /><?php<br />// Show IF Conditional region_check_user_age<br />if ($birthday_user < 20) {<br />?> <br />display banner for folks under 20 <br /><?php<br />// else Conditional region_check_user_age<br />} else { ?> <br />display banner for folks older than 20 <br /><?php }<br />// endif Conditional region_check_user_age<br />?> <br /> <br />As the line breaks in the code posted above will most likely disappear as before, I´m attaching a text-only version <br /> <br />Cheers, <br />Günter Schenk <br />Adobe Community Expert, Dreamweaver
                          • 10. Re: edit session value after login
                            Level 1
                            Günter, thanks again for your contribution.
                            Adobe should be very thankfull for your help here on the board :)

                            Thanks also for your thoughts.
                            But i think this is not the best solution for this isue.
                            This means that for every visitor the server needs to do this conversion on every page they visit. My website has an avarage pageview of 30 pages per visitor. At the moment we have about 550 visitors a day but we are going to run a campain to get at least 5000 visitors a day.
                            I think you see why for this case it would be better to have the final session value upon login instead of asking the server every page to see if i am still 38 :)

                            So i am trying to route through the routines to find the right place where the sessions are set and i can savely change their value.

                            I you have any other idea, please share i with me.

                            Thanks,
                            Jim

                            ps: i don't have to figure out what banner to show. All that is done by the banner system. All i have to do is pass through the values.
                            • 11. Re: edit session value after login
                              Günter Schenk Level 4
                              Hi Jim,

                              thanks, that makes it clear to me.

                              ------
                              This means that for every visitor the server needs to do this conversion on every page they visit
                              ------

                              sure, but as on every page you´ll anyway need to check...

                              a) if the session actually exists or not, plus
                              b) check at least whatever session variable, plus
                              c) do one or more if-else checks for the appropriate banner

                              ...regardless of the chosen conversion method, you can trust me that this pretty tiny "on the fly" conversion of this very session variable alone is not even capable to add some really noticeable strain on the server´s performance -- if any, I would worry about other stuff, but not this :-)

                              --------
                              to get at least 5000 visitors a day
                              --------

                              alright, let´s do some math :: 24 hours are - umm - 1440 minutes respectively 86400 seconds, and as all your expected 5000 visitors will mostly likely not be loading whatever page in the very same second, I really wonder what you´re worrying about :-)

                              However, we´re talking about a sort of strain that´s possibly put on the server in regards to executing PHP related stuff -- and it must be said that e.g. one real estate site I did for a customer has both approx. the same amount of daily visitors plus has *much* more PHP related stuff (multiple database queries, several "on the fly" exchange rate conversions of a price that´s stored in one column, 132 database table to query from) going on per page, and that´s all getting processed on a rather "average" shared hosting.

                              Cheers,
                              Günter Schenk
                              Adobe Community Expert, Dreamweaver
                              • 12. Re: edit session value after login
                                Level 1
                                well you are probably right Günter.

                                Last week we had a rush on our website because of a newsletter we got on and that evening the server stopped responding.
                                The website is very dynamic with user generated content, voting uploading downloading, lists with new/popular items etc...

                                So that got me started thinking about every little thing that can be optimized.
                                Now all of a sudden I need to study how to cache pages...

                                I am not sure how many and what kind of other websites were running on that shared server but it did make me panick.

                                It is also just that for my feeling all that can be done in one move is better than to do it on every page...

                                And you are right, I probably have other thinks i should worry about.

                                Thanks,
                                Jim