Sessions Not Being Created As Desired

 

Results 1 to 9 of 9
Hi I am looking to create a site where a session lasts 30 minutes. There ...
  1. #1
    PopUnder is offline Newbies
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    6
    Thanked 4 Times in 4 Posts

    Default Sessions Not Being Created As Desired

    Hi

    I am looking to create a site where a session lasts 30 minutes. There is a session table that is updated with a list of new sessions. I have the following thing coded. But I noticed that there are over 213 sessions created although the test-site only had 23 pageviews from 10 visits or so (which means 10 sessions at the maximum). Could you please tell me where I am going wrong that there were over 213 sessions created in one day?

    HTML Code:
          session_start();
          $result=mysql_query("SELECT * FROM $database_name.sessiontable_name WHERE id='".session_id()."';",$databaseconnect);
          $row = mysql_fetch_array($result);
          $id=$row["id"];
          $b=false;
          if(count($id)==0){
                $t=date("i");
                $id=session_id();
                $q="INSERT INTO $database_name.sessiontable_name (id, timesession) VALUES (\"$id\", $t);";
                mysql_query($q);
                $b=true;
     
          }
          else{
                $t=intval($row["timesession"]);
                if(abs($t-intval(date("i")))>30){
                $t=date("i");
                      $id=session_id();
                      mysql_query("UPDATE $database_name.sessiontable_name SET timesession=$t WHERE id=\"$id\";");
                      $b=true;
                }     
          }
     




  2. #2
    jazzc's Avatar
    jazzc is offline Programming & Web Design Moderator black hat forumsblack hat forumsblack hat forums
    Join Date
    Jan 2009
    Posts
    2,184
    Thanks
    6,090
    Thanked 7,042 Times in 2,496 Posts

    Default Re: Sessions Not Being Created As Desired

    Are you using multiple connections? The first mysql query has a resource parameter while the others don't.

  3. The Following User Says Thank You to jazzc For This Useful Post:

    PopUnder (01-09-2013)

  4. #3
    PopUnder is offline Newbies
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    6
    Thanked 4 Times in 4 Posts

    Default Re: Sessions Not Being Created As Desired

    Apologies if I am not helping you with the correct reply. I am not a programmer, just trying to debug the code a developer wrote for me:

    By resource parameter, I am assuming it's the $databaseconnect variable you are referring to. It's defined as this in the relevant connection file:

    HTML Code:
            $databaseconnect = mysql_connect("localhost", "root", "");  
            $databaseconnect = mysql_connect("localhost", "username", "password");
    Would you count this as two resources?

    Would it help if I added the resource parameter to the end of the other mysql queries as well?

  5. #4
    jazzc's Avatar
    jazzc is offline Programming & Web Design Moderator black hat forumsblack hat forumsblack hat forums
    Join Date
    Jan 2009
    Posts
    2,184
    Thanks
    6,090
    Thanked 7,042 Times in 2,496 Posts

    Default Re: Sessions Not Being Created As Desired

    Hi, thanks for the clarification,

    It 's 1 resource, although there 's not reason to have it declared twice. You can keep the line that has the correct username and password (i suppose the 2nd one) and delete the other.

    Let 's try something:

    Create 2 files on the same site (e.g. test1.php and test2.php) with the following content on both
    Code:
    <?php
    
    session_start();
    echo session_id();
    
    ?>
    Now, open test1.php and then open test2.php.

    Is the output the same in both cases?

  6. The Following User Says Thank You to jazzc For This Useful Post:

    PopUnder (01-09-2013)

  7. #5
    PopUnder is offline Newbies
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    6
    Thanked 4 Times in 4 Posts

    Default Re: Sessions Not Being Created As Desired

    Hi Jazzc,

    Tried it..Yes, when tested from the same browser, it shows the same session id on both test1.php and test2.php

  8. #6
    jazzc's Avatar
    jazzc is offline Programming & Web Design Moderator black hat forumsblack hat forumsblack hat forums
    Join Date
    Jan 2009
    Posts
    2,184
    Thanks
    6,090
    Thanked 7,042 Times in 2,496 Posts

    Default Re: Sessions Not Being Created As Desired

    Next one

    Add var_dump($row); after the $row = line, browse a bit and see if it 's always false or not.

  9. #7
    PopUnder is offline Newbies
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    6
    Thanked 4 Times in 4 Posts

    Default Re: Sessions Not Being Created As Desired

    I have added it on my code. But could you clarify where I need to check this? Thanks a lot for the help.

  10. #8
    jazzc's Avatar
    jazzc is offline Programming & Web Design Moderator black hat forumsblack hat forumsblack hat forums
    Join Date
    Jan 2009
    Posts
    2,184
    Thanks
    6,090
    Thanked 7,042 Times in 2,496 Posts

    Default Re: Sessions Not Being Created As Desired

    var_dump dumps the content of the variable in the html page. If it 's not viewable directly, try doing view source on the browser.

    For example, var_dump($i_do_not_exist); would display NULL

    To help you locate it if you have a lot of output you can also add a echo 'VAR_DUMP RESULT FOLLOWS<br>'; directly before it.

  11. The Following User Says Thank You to jazzc For This Useful Post:

    PopUnder (01-09-2013)

  12. #9
    PopUnder is offline Newbies
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    6
    Thanked 4 Times in 4 Posts

    Default Re: Sessions Not Being Created As Desired

    Hi Jazzc

    Thanks a lot for all the help. Apparently, the bug was because of another script mistake and did not have anything to do with session IDs. Sorry for taking your time.

  13. The Following User Says Thank You to PopUnder For This Useful Post:

    jazzc (01-09-2013)


Similar Threads

  1. Any good email service around with desired domain???
    By dev007 in forum Black Hat SEO
    Replies: 0
    Last Post: 01-17-2012, 10:24 AM
  2. SETTING desired youtube thumbnails
    By trevorhoang in forum YouTube
    Replies: 2
    Last Post: 05-19-2011, 03:00 AM
  3. Account Creation Desired - 2 Fields
    By MoreMoneyMoreProblem in forum Hire a Freelancer
    Replies: 3
    Last Post: 03-29-2011, 07:33 PM
  4. how to integrate blog into a desired page
    By bbillings in forum Blogging
    Replies: 2
    Last Post: 03-14-2011, 10:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108