Jump to content

[SOLVED] How do you make an update, then destroy the session?


Recommended Posts

Hi Guys,

 

I'm trying add "change your username and email address" functionality to my site.

 

The Username is a Session Variable that is set when the user logs in.

 

Users log in with their email address and password.

 

I think when the update their username, the session should be destroyed and they should log back in, right?

 

Can you help proof what I have below? Should I add

 

if ($_SESSION[user_id]) {

 

and delete a couple brackets?

 

With the code below I'm getting these errors:

Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in ... and

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

 

Thank you very much for your help!

 

Here's what I have:

 

<?php
include_once ("contentdb.php"); // database connection
include_once ("nav_home_login.inc");

if ($_POST[submit]) {

// validation 
if ($_POST[email] <> "") {
	$a = TRUE;
} else {
	$a = FALSE;
	$content .= "<p>Please enter your email address.</p>\n";
}
if ($_POST[user_name] <> "") {
	$b = TRUE;
} else {
	$b = FALSE;
	$content .= "<p>Please enter your username.</p>\n";
}

// check to see if the user_name is in use

$usercheck = $_POST[user_name];
$check = mysql_query("SELECT * FROM registered_users WHERE user_name = '$usercheck'")or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists give an error
if ($check2 != 0) {
$c = FALSE;
$content .= "<p>Sorry, that username is already in use.</p>\n";
} else {
	$c = TRUE;
}


if ($a AND $b AND $c) { 

$query = "UPDATE registered_users SET registered_users.user_name = '$_POST[user_name]', registered_users.email ='$_POST[email]' WHERE registered_users.id = '" . $_SESSION['user_id'] . "'";	

if (mysql_query($query)) {

$recep = "$_POST[email]";
$subject = "Changes to Account Details";
$text = "Dear $_POST[user_name],
Your account details have been updated:

email: $_POST[email]
username: $_POST[user_name]

Best Regards,
Ryan
";
$headers2 = "MIME-Version: 1.0\r\n";
$headers2 .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers2 .= "Reply-to: ryandetwiler@eslvideo.com\n";
$headers2 .= "X-Mailer: PHP\n";
mail($recep2,$subject2,$text2,$headers2);


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

$content .= "<h2>Your Account details have been successfully updated. Please log back in with your email address and password.

<br><br><p>
<form action = 'login_process.php' method = 'POST'>
<b>Email:</b> <input type = 'text' name = 'email' size = '20' maxlength = '30'> 
     
<b>Password:</b> <input type = 'password' name = 'password' size = '10' maxlength = '15'>
     
<input type = 'submit' name = 'submit' value = 'Login'>
</form>
</p>
<br>
";
}
     else {

$content .= "<p>your changes could not be completed at this time.<br></p>";

}			
} 
else { 

$content .= '<p>Please click your browser\'s [back] button to return to the form.<br></p>';
}	
} 

include_once ("template_my_account_edit_details_pro.inc"); 

?>

 

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.