Jump to content

Having problems with unsetting a SESSION


barbs75

Recommended Posts

Ok,

 

The problem i am having is with unsetting a SESSION.

 

What i have is a login system, where the user can login, then go to a profile page where they can edit their info, change thier password and then cancel their account.

 

When they go to the cancel page, they have to re-enter their password, and then this and their username is checked against the database, and if it is found, the record is deleted.

 

The problem i am having is with my form helper. When the user enteres their password and username on the cancel page(cancelmembership.php) the form is processed in cancel.php which then generates an array to store errors in, called '$deleteerrorarray', this is then stored into a session named '$_SESSION['deleteerror_storage']' this is then retrieved when the user makes an error and is sent back to the cancelmembership.php page, and displays the error. This all works, but when they make an error, and then say, leaves this page, and comes back, the error box is still there, when they leave i want the error box to disappear.

 

Now, i have used 'unset($_SESSION['deleteerror_storage']) after the session is used to output the error, so that it is unset, so when they leave the page and come back to it, the session shouldnt be retrievable and therefore the error box doesnt appear?!?

 

Am i right in saying that?? 'cause it sure as hell doesnt work!!

 

I have been trying everything, putting the unset in different places and stuff, but nothing works...really cant figure out the problem??

 

here is my code:

 

cancelmembership.php

<?php
//starts session and checks loggin status 
session_start(); 
header("Cache-control: private"); 
if (!$_SESSION['username']) { 
    include("login_form.php"); 
    exit(); 
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="Style1.css" />
<link rel="shortcut icon" href="Images/favicon3.ico" type="image/x-icon"/>
<title>Your profile Settings</title>

<meta name="Description" content="Find your dream property online, Search for any property for
sale in a range of areas in the UK with go4home" />
    
<meta name="Keywords" content="Find a property, find property, find property in UK,
search for a property, Property up for sale, find property up for sale, Property market,
    Advertise your home to sell, go4home.co.uk, go4home" />
    

</head>

<body>
<div id="mainContainer">
<div id="container-Content">
    	<div id="content-TopContent">
            <div id="TopBar" class="orangeBar">
            <div id="Logo"><img src="Images/Go4Home-logo.jpg" alt="Go4home.co.uk" width="201" height="39" /></div>
            <div id="myProfileuserlogin">
            <div id="profilelogo"><img src="Images/profilelogo.png" /></div>
            <div id="userInfo"><?php echo "hello, ".$_SESSION['username'];?></div>
            </div>
            <div id="Login" class="Logout"><a href="logout.php">logout</a></div>
            <ul id="profilemenu">
            	<li><a class="blue" href="settings.php">Your Profile</a></li>
            	<li><a class="blue" href="construction Page.html">Saved Properties</a></li>
            </ul>
            </div>
      <!--End of TopBar -->
            <ul id="navigationMenu">
                <li class="HomeButton"><a href="index.php"></a></li>
                <li class="SearchButton"><a href="Construction Page.html"></a></li>
                <li class="MoneyMarketButton"><a href="Construction Page.html"></a></li>
                <li class="GoBuyButton"><a href="Construction Page.html"></a></li>
                <li class="GoSellButton"><a href="Construction Page.html"></a></li>
                <li class="HelpButton"><a href="Construction Page.html"></a></li>
            </ul>
        </div><!--End of content-Topcontent -->
<div id="profileBar">
        <div id="userInfoLarge"><h2 class="shadow"><?php echo $_SESSION['username'] ?></h2></div>
        <div id="userInfoLogoLarge"><img src="Images/UserlogoLARGE.png" /></div>
        <div id="profileTitle"><h2 class="shadow">Your Profile</h2></div>
    </div><!--End of profileBar-->

<div id="content-bodycontent">
    	<div id="Redcontentwindow">
       		<div class="Redwindowtop">
            	<div id="headerLogo"><img src="Images/cancelLogo.png" /></div>
            	<span><h5>Cancelling Your Membership</h5></span>
            </div>
            <div class="Redwindowbody">
                <p class="largeblue"><strong>We hate to see you walk out the door!</strong></p>
                <hr />
                <p class="largeblue">
                	We would love for you to tell us how we can better your experience with us @ go4home<br />
                    if you want, drop us an email and do just that!<br /><br />
                    Please verify your password below to deactivate your account.
                </p>
                <br />
			<?php
                    if (isset($_SESSION['deleteerror_storage']))
                    {
                        $strError = '<div class="formerror"><p class="error"><img src="/images/warningtriangle.png">Please check the following and try again:</p><ul>';
                    // Get each error and add it to the error string 
                    // as a list item.
                    foreach ($_SESSION['deleteerror_storage'] as $error) {
                        $strError .= "<li>$error</li>";
                    }
                    $strError .= '</ul></div>';
                    echo $strError;
                    }
				//unset deleteerror_storage session
				unset($_SESSION['deleteerror_storage']);
                ?>
                <div id="submitCustomerForm">
                <FORM ACTION="cancel.php" METHOD="POST" NAME="contact_form">
                  <div id="inputfield">
			  	  <label for="username" class="blue"><strong>Your Username:</strong></label>
				  <input class="fade" name="username" type=text size="50" maxlength="12" id="username" value="<?php echo $_SESSION['username']?>">
                  </div>
                  <div id="inputfield">  
                      <label for="password" class="blue"><strong>Your Password:</strong></label>
                      <input class="fade" name="password" type=password size="50" maxlength="12" id="password" value="">
			  </div>
                    <br />
				<input type="image" src="Images/cancelbutton.png" align="right" name="Submit" />
                    <br />
                    <br />
              </FORM>
              </div>
         </div>
            <div class="Redwindowbottom"><span></span></div>
       </div>
    </div><!--End of content-bodycontent"-->
    </div>

    
    <div id="footer">
    <ul id="footerMenu">
        <li><a href="Construction Page.html">Go4home terms & conditions</a></li>
        <li><a href="Construction Page.html">Accessibility</a></li>
        <li><a href="Construction Page.html">About Us</a></li>
        <li><a href="Construction Page.html">Privacy Policy</a></li>
        <li><a href="Construction Page.html">Contact Us</a></li>
    </ul>
<div id="CopyrightText"></div>
</div><!--End of footer-->
</div><!--End of mainContainer-->
</body>
</html> 

 

cancel.php

<?php
//starts session and checks loggin status 
session_start(); 
header("Cache-control: private"); 
if (!$_SESSION['username']) { 
    include("login_form.php"); 
    exit(); 
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="Style1.css" />
<link rel="shortcut icon" href="Images/favicon3.ico" type="image/x-icon"/>
<title>Cancel your membership</title>

<meta name="Description" content="Find your dream property online, Search for any property for
sale in a range of areas in the UK with go4home" />
    
<meta name="Keywords" content="Find a property, find property, find property in UK,
search for a property, Property up for sale, find property up for sale, Property market,
    Advertise your home to sell, go4home.co.uk, go4home" />
    

</head>
<?php

//delete customer record from database

//store posted values into vaiables
$username = $_POST['username'];
$password = $_POST['password'];

//create array to hold errors
//$deleteerrorarray = array();

include('database.php');

//double check user exists beofore deleting their account
$sql_user_check    = "SELECT * FROM customer WHERE username='$username' and encryptpass = '".md5($password)."' and status = 1"; 
$result_name_check = mysql_query($sql_user_check); 
$usersfound        = mysql_num_rows($result_name_check); 

if ($usersfound < 1) { 
    $deleteerrorarray['nouser'] = "User $user not found. You may have entered incorrect username and or password, or your account may not be active"; 

    if ($deleteerrorarray) { 
       $_SESSION['deleteerror_storage']=$deleteerrorarray; 
       header('Location: cancelmembership.php');
   //echo $usersfound; 
       die(); 
    }
// if user does exist, continue and delete user
} else { //else1

mysql_query("DELETE FROM customer WHERE username='$username' and encryptpass = '".md5($password)."'"); 

//after that destroy the session
$_SESSION = array();
session_destroy();
//mysql_close($con);
include('index.php');
}
?>

 

If anyone could have a little look, anyone see what i need to do here? because i cant figure it out...

 

cheers guys

 

Craig

Link to comment
Share on other sites

unset($_SESSION['deleteerror_storage']) does not destroy the session, it only unsets the session variable deleteerror_storage. you appear to destroy the session properly elsewhere in your code:

 

//after that destroy the session
$_SESSION = array();
session_destroy();

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.