•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,539 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,261 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1813 | Replies: 13 | Solved
![]() |
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 173
Reputation:
Rep Power: 1
Solved Threads: 2
php Syntax (Toggle Plain Text)
<?php session_start(); session_unset('YourVisitID'); session_destroy(); header("location:index.php"); ?>
I've use the code above to destroy my session after login, but instead of destroying it, It creates another session called 'PHPSESID'. I'm using XAMPP localhost. Please advise.*
* page redirection works fine
"I might not be the BEST but I'm not like the REST!"
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 173
Reputation:
Rep Power: 1
Solved Threads: 2
I'm using Mozilla Firefox. After I logged it, I checked the cookies, there will only 'YourVisitID' under localhost. Then when I press log out button, It will redirect me back to the i.dex.php. Then I tried to copy & paste the direct link to the admin's page., it still works. then I went to check the cookies again, and what I saw under localhost was the intial session 'YourVisitID' was still there and not destroyed and there will be another cookie named 'PHPSESID'.
Advise please.
Advise please.
"I might not be the BEST but I'm not like the REST!"
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Are you validating existence of session in admin's page ? Try ths simple example.
This is page2.php
Well, if you try to access page2.php directly, you will get Invalid session. Are you doing a check like this one in admin's page ?
php Syntax (Toggle Plain Text)
<?php //page1.php session_start(); $_SESSION['name']="test"; echo "<a href='page2.php'>Click here</a>"; ?>
php Syntax (Toggle Plain Text)
<?php session_start(); if(!empty($_SESSION['name'])){ echo $_SESSION['name']; } else { echo "Invalid session"; } ?>
Last edited by nav33n : Feb 28th, 2008 at 12:07 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 5
Here is what I do
secure.php
logout.php
secure.php
<?php
session_start();
if (empty($_SESSION['username'])) {
header("location:index.php");
exit; }
?>logout.php
<?php
session_start();
if($_SESSION["status"]="logged") {
session_unset();
session_destroy();
header( "Location:../index.php" );
exit();
} else {
if ($_SESSION["status"]="not logged") {
//the session variable isn't registered, the user shouldn't even be on this page
header( "Location:../index.php" );
exit();
}
}
?>•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 173
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
I'm using Mozilla Firefox. After I logged it, I checked the cookies, there will only 'YourVisitID' under localhost. Then when I press log out button, It will redirect me back to the i.dex.php. Then I tried to copy & paste the direct link to the admin's page., it still works.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Apr 2005
Location: New York state
Posts: 465
Reputation:
Rep Power: 5
Solved Threads: 72
php Syntax (Toggle Plain Text)
<?php session_start(); if($_SESSION["status"]="logged") { session_unset(); session_destroy(); header( "Location:../index.php" ); exit(); } else { if ($_SESSION["status"]="not logged") { //the session variable isn't registered, the user shouldn't even be on this page header( "Location:../index.php" ); exit(); } } ?>
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 173
Reputation:
Rep Power: 1
Solved Threads: 2
login.php
loggedin.php(admin page)
Advise pls.
php Syntax (Toggle Plain Text)
<?php // Send NOTHING to the Web browser prior to the session_start() line! // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for an email address. if (empty($_POST['username'])) { $errors[] = 'You forgot to enter your Username.'; } else { $u = escape_data($_POST['username']); } // Check for a password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your password.'; } else { $p = escape_data($_POST['password']); } if (empty($errors)) { // If everything's OK. /* Retrieve the user_id and first_name for that email/password combination. */ $query = "SELECT user_id, first_name FROM adminprofile WHERE username='$u' AND password='$p'"; $result = @mysql_query ($query); // Run the query. $row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable. if ($row) { // A record was pulled from the database. // Set the session data & redirect. session_name ('YourVisitID'); session_start(); $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect the user to the loggedin.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. //$url .= 'loggedin.php'; //header("Location: $url"); header("Location: loggedin.php"); exit(); // Quit the script. } else { // No record matched the query. $errors[] = 'The username and password entered do not match those on file.'; // Public message. $errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message. } } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional. // Begin the page now. $page_title = 'Login'; include ('./includes/header.html'); if (!empty($errors)) { // Print any error messages. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } // Create the form. ?> <h2>Login</h2> <form action="login.php" method="post"> <p>Username: <input type="text" name="username" size="20" maxlength="15" /> </p> <p>Password: <input type="password" name="password" size="20" maxlength="15" /></p> <p><input type="submit" name="submit" value="Login" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.html'); ?>
loggedin.php(admin page)
php Syntax (Toggle Plain Text)
<?php # User is redirected here from login.php. session_name ('YourVisitID'); session_start(); // Start the session. // If no session value is present, redirect the user. if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } //$url .= 'index.php'; // Add the page. //header("Location: $url"); header("Location: index.php"); exit(); // Quit the script. } // Set the page title and include the HTML header. $page_title = 'Logged In!'; include ('./includes/header1.html'); // Print a customized message. echo "<h1>Logged In!</h1> <p>You are now logged in, {$_SESSION['first_name']}!</p> <p><br /><br /></p>"; include ('./includes/footer.html'); ?>
Advise pls.
"I might not be the BEST but I'm not like the REST!"
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Maybe this isn't working. Print some statements inside this loop and execute this script (without logging in).
if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) {
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Re-authenticating User Problem (PHP)
- PHP MySQL problem (PHP)
- timeout session problem (JSP)
- Facing the problem on "RedirectFromLoginPage" (VB.NET)
- inet20099 Problem (Viruses, Spyware and other Nasties)
- Netscape 7.1, Hotmail login problem - cookies 'disabled" (Windows NT / 2000 / XP / 2003)
- computer lagging...hijack this log, please help (Viruses, Spyware and other Nasties)
- Mystery IE Session Freezes (Web Browsers)
- Possible CWS problem (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: hide textarea
- Next Thread: Hidden variable in php



Linear Mode