473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to completely end sessions..

3
i do having this problems.. once log out the data from database still come out but the table structure already invisible..

how to completely disconnect from database when session end..

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. define('INCLUDE_CHECK',true);
  4.  
  5. require 'connect.php';
  6. require 'functions.php';
  7. // Those two files can be included only if INCLUDE_CHECK is defined
  8.  
  9. // select record from mysql 
  10. $sql="SELECT * FROM $tbl_name";
  11. $result=mysql_query($sql);
  12.  
  13. session_name('Login');
  14. session_set_cookie_params(2*7*24*60*60);
  15. session_start();
  16.  
  17. ?>
  18.  
  19. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  20. <html xmlns="http://www.w3.org/1999/xhtml">
  21.  
  22. <head>
  23. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  24. <title>Administrator Control Panel only!</title>
  25.  
  26.     <link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
  27.  
  28. </head>
  29.  
  30. <body>
  31.  
  32. <div id="main">
  33.   <div class="container">
  34.     <h1>Registered Administrator Only!</h1>
  35.     <h2>Login to view this resource!</h2>
  36.     </div>
  37.  
  38.     <div class="container">
  39. <?php
  40.     if($_SESSION['id'])
  41.     echo '
  42.  
  43. <table width="100%" border="0" cellspacing="1" cellpadding="0">
  44. <tr>
  45. <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  46. <tr>
  47.  
  48. <td colspan="8" bgcolor="#FFC600"><strong><center>Delete Temporary User & Password Here!</center></strong> </td>
  49. </tr>
  50. <tr>
  51. <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
  52. <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
  53. <td align="center" bgcolor="#FFFFFF"><strong>Pass</strong></td>
  54. <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
  55. <td align="center" bgcolor="#FFFFFF"><strong>IP Address</strong></td>
  56. <td align="center" bgcolor="#FFFFFF"><strong>Date</strong></td>
  57. <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  58. <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  59. </tr>';
  60.     else echo '<h1>Unauthorize Area</h1>';
  61.     ?>
  62.  
  63. <?php
  64. while($rows=mysql_fetch_array($result)){
  65. ?>
  66. <tr>
  67. <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
  68. <td bgcolor="#FFFFFF"><? echo $rows['usr']; ?></td>
  69. <td bgcolor="#FFFFFF"><? echo $rows['pass']; ?></td>
  70. <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
  71. <td bgcolor="#FFFFFF"><? echo $rows['regIP']; ?></td>
  72. <td bgcolor="#FFFFFF"><? echo $rows['dt']; ?></td>
  73. <td bgcolor="#FFFFFF"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
  74. <td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>"><font color="#FF0000">delete</font></a></td>
  75. </tr>
  76.  
  77.  
  78. <?
  79.  
  80. // close while loop 
  81. }
  82.  
  83. // close connection; 
  84. mysql_close();
  85.  
  86. ?> 
  87. </table></td>
  88. </tr>
  89. </table>
  90.  
  91. </div>
  92.  
  93.  
  94. </body>
  95. </html>

thank you...
Oct 7 '10 #1
4 1658
dlite922
1,584 Expert 1GB
Where do you log out? Where's the code that destroys the session?

I don't understand what session has to do with the database.

You can destroy a variable using unset() if you like.

mysql_close() will close the connection, It won't get rid of the data you have already put in to a variable, like $result.


Dan
Oct 7 '10 #2
bulp
3
Thank You Dan for the response.. :)

my bad.. sorry this is the login and log out code..

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. define('INCLUDE_CHECK',true);
  4.  
  5. require 'connect.php';
  6. require 'functions.php';
  7. // Those two files can be included only if INCLUDE_CHECK is defined
  8.  
  9.  
  10. session_name('Login');
  11. // Starting the session
  12.  
  13. session_set_cookie_params(2*7*24*60*60);
  14. // Making the cookie live for 2 weeks
  15.  
  16. session_start();
  17.  
  18. if($_SESSION['id'] && !isset($_COOKIE['Remember']) && !$_SESSION['rememberMe'])
  19. {
  20.     // If you are logged in, but you don't have the Remember cookie (browser restart)
  21.     // and you have not checked the rememberMe checkbox:
  22.  
  23.     $_SESSION = array();
  24.     session_destroy();
  25.  
  26.     // Destroy the session
  27. }
  28.  
  29.  
  30. if(isset($_GET['logoff']))
  31. {
  32.     $_SESSION = array();
  33.     session_destroy();
  34.  
  35.     header("Location: index.php");
  36.     exit;
  37. }
should i create the logout button into the data page that i paste earlier ?
Oct 7 '10 #3
rythmic
29
Hi!

Here is the problem. You check whether a user is logged in or not, but no matter the response you still echo the table data.

Echoing the table data should also be constrained by the if($_SESSION['id']) statement

Your code should look like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  <?php
  4.  
  5.     define('INCLUDE_CHECK',true);
  6.  
  7.     require 'connect.php';
  8.     require 'functions.php';
  9.     // Those two files can be included only if INCLUDE_CHECK is defined
  10.  
  11.     // select record from mysql 
  12.    $sql="SELECT * FROM $tbl_name";
  13.    $result=mysql_query($sql);
  14.  
  15.    session_name('Login');
  16.    session_set_cookie_params(2*7*24*60*60);
  17.    session_start();
  18.  
  19.    ?>
  20.  
  21.    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  22.    <html xmlns="http://www.w3.org/1999/xhtml">
  23.  
  24.    <head>
  25.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  26.    <title>Administrator Control Panel only!</title>
  27.  
  28.        <link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
  29.  
  30.    </head>
  31.  
  32.    <body>
  33.  
  34.    <div id="main">
  35.      <div class="container">
  36.        <h1>Registered Administrator Only!</h1>
  37.        <h2>Login to view this resource!</h2>
  38.        </div>
  39.  
  40.        <div class="container">
  41.    <?php
  42.        if($_SESSION['id'])
  43.        echo '
  44.  
  45.    <table width="100%" border="0" cellspacing="1" cellpadding="0">
  46.    <tr>
  47.    <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  48.    <tr>
  49.  
  50.    <td colspan="8" bgcolor="#FFC600"><strong><center>Delete Temporary User & Password Here!</center></strong> </td>
  51.    </tr>
  52.    <tr>
  53.    <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
  54.    <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
  55.    <td align="center" bgcolor="#FFFFFF"><strong>Pass</strong></td>
  56.    <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
  57.    <td align="center" bgcolor="#FFFFFF"><strong>IP Address</strong></td>
  58.    <td align="center" bgcolor="#FFFFFF"><strong>Date</strong></td>
  59.    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  60.    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
  61.    </tr>';
  62.        else echo '<h1>Unauthorize Area</h1>';
  63.        ?>
  64.  
  65.    <?php
  66.    if($_SESSION['id']){ // you can put it here to not execute the while loop at all for non-logged in users
  67.    while($rows=mysql_fetch_array($result)){
  68.    ?>
  69.    <tr>
  70.    <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
  71.    <td bgcolor="#FFFFFF"><? echo $rows['usr']; ?></td>
  72.    <td bgcolor="#FFFFFF"><? echo $rows['pass']; ?></td>
  73.    <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
  74.    <td bgcolor="#FFFFFF"><? echo $rows['regIP']; ?></td>
  75.    <td bgcolor="#FFFFFF"><? echo $rows['dt']; ?></td>
  76.    <td bgcolor="#FFFFFF"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
  77.    <td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>"><font color="#FF0000">delete</font></a></td>
  78.    </tr>
  79.  
  80.  
  81.    <?
  82.  
  83.    // close while loop 
  84.    }
  85.    // Rythmic input!!!: end if-statement
  86.    } // here you could include an else statment if you want something displayed to non-logged in users
  87.  
  88.    // close connection; 
  89.    mysql_close();
  90.  
  91.    ?> 
  92.   </table></td>
  93.   </tr>
  94.   </table>
  95.  
  96.    </div>
  97.  
  98.  
  99.    </body>
  100.  </html>
  101.  
  102.  
  103.  
as a side note maybe you should also consider a stronger check than just checking that an id exists to determine whether a user may view your resource or not.
Oct 10 '10 #4
bulp
3
rythmic...

thanks for the response but ur code seems totally block the access to data.. i mean even when im log in.. the data didnt show at all..
Oct 21 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Yoyoma_2 | last post by:
Hello, i'me having a wierd problems with sessions. PHP 4.3.3, Register globals is on, and the sessions module is installed. if i have a page like this: <? session_start(); $_SESSION="blue";...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
1
by: Eagleprof | last post by:
Hi, This one has me completely stumped. I have a simple site where I'm using sessions to keep track of some information across multiple pages. The trouble is, when I go to a page that displays...
3
by: LMachado1 | last post by:
I just started with php and I'm trying to make a simple interface as follows: - user is asked to input an integers, for example: how many students do you want to enter? - user is then shown a...
17
by: Peter Chant | last post by:
Am I right in assuming that when I connect from one browser, using several tabs to a database produced in mysql/php/apache only uses one session for all tabs? I have been loosing records from my...
9
by: AndersBj | last post by:
Hi all, I have a web application that uses State Server for session handling. The web application randomly loses all session variables. The sessions are not always lost, sometimes I can use the...
3
by: Dave Smithz | last post by:
Hi there, I have a website where users can log into. This users sessions as I believe most people use when implementing a login section of a website (each php page first checks a valid parameter...
4
by: news | last post by:
We have a huge PHP e-commerce site that relies totally on PHP sessions and cookies. We need to create a demo version of the site for potential clients to use that does NOT show the original URL in...
3
by: AlonR | last post by:
Hi, We're experiencing random user sessions losses on our web applications, and are researching for any useful information which may shed light on this problem. Environment: In our...
3
by: Jon Slaughter | last post by:
Any pitfalls or stuff I need to worry about when working with sessions? I want to write a log file and hit counter along with a login interface and I'm trying to learn this stuff. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.