alwaysinit Posted January 21, 2007 Share Posted January 21, 2007 Hi again masterminds, I would like to see if someone can make this work for me.I got it from the "session_destroy" function at PHP.net(I need this function terribly)If you need any information from me, just let me know. I'm trying to clear out some Mysql variables that were previously defined in the user's session. So when they navigate back to the form from the parse, their information shows their changes without having them shut down their browser.Basically looking for a way to 'log them out', 'then back in' in the same script. Without that, their MySQL info won't show change back in the form page.[code]<?phpsession_start();// Some simple code etc etc$requested_logout = true;if ($requested_logout) { session_restart();}// Now the session_id will be different every browser refreshprint(session_id());function session_restart(){ if (session_name()=='') { // Session not started yet session_start(); } else { // Session was started, so destroy session_destroy(); // But we do want a session started for the next request session_start(); session_regenerate_id(); // PHP < 4.3.3, since it does not put setcookie(session_name(), session_id()); }}?>[/code] Quote Link to comment Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 alwaysinit, why not replace the session variables instead of unsetting and resetting them??and redirect them to the form, not send them back. Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted January 21, 2007 Author Share Posted January 21, 2007 [quote author=inztinkt link=topic=123382.msg509853#msg509853 date=1169398645]alwaysinit, why not replace the session variables instead of unsetting and resetting them??and redirect them to the form, not send them back. [/quote]thanks inztinkt, I'm still wet behind the ears, could you help me code the replace and redirect. here is my "infoparse.php"(form.php" is where the data gets displayed in this case):[code]<?php session_start(); header("Cache-Control: no-cache, must-revalidate"); if (!$_SESSION['id']) { echo "You're not logged in!"; include("doh.html"); exit(); } $id = $_SESSION['id'];// Connect to Mysql include ("mysql_conn.php"); if ($_POST['artname'] != "") { $artname = htmlspecialchars($_POST['artname']); mysql_query("UPDATE users SET name='$artname' WHERE id='$id'") or die (mysql_error()); $_SESSION['artname'] = $artname; $cartname = "<li>artname</li>"; } if ($_POST['country'] != "") { $country = htmlspecialchars($_POST['country']); mysql_query("UPDATE users SET country='$country' WHERE id='$id'") or die (mysql_error()); $_SESSION['country'] = $country; $ccountry = "<li>country</li>"; } if ($_POST['province'] != "") { $province = htmlspecialchars($_POST['province']); mysql_query("UPDATE users SET province='$province' WHERE id='$id'") or die (mysql_error()); $_SESSION['province'] = $province; $cprovince = "<li>province</li>"; } if ($_POST['city'] != "") { $city = htmlspecialchars($_POST['city']); mysql_query("UPDATE users SET city='$city' WHERE id='$id'") or die (mysql_error()); $_SESSION['city'] = $city; $ccity = "<li>city</li>"; } if ($_POST['bio'] != "") { $bio = nl2br(htmlspecialchars($_POST['bio'])); mysql_query("UPDATE users SET bio='$bio' WHERE id='$id'") or die (mysql_error()); $_SESSION['bio'] = $bio; $cbio = "<li>bio</li>"; } if ($_POST['infl'] != "") { $infl = nl2br(htmlspecialchars($_POST['infl'])); mysql_query("UPDATE users SET infl='$infl' WHERE id='$id'") or die (mysql_error()); $_SESSION['infl'] = $infl; $cinfl = "<li>influences</li>";} ?> <html><head><title>Change Profile Results</title></head><body> <h1>Change Profile Results:</h1> <?if (($cartname) || ($ccountry) || ($cprovince) || ($ccity) || ($cbio) || ($cinfl)) { echo "The following items have been updated in your profile:<br /><ul>"; if ($cartname) { echo $cartname; } if ($ccountry) { echo $ccountry; } if ($cprovince) { echo $cprovince; } if ($ccity) { echo $ccity; } if ($cbio) { echo $cbio; } if ($cinfl) { echo $cinfl; } echo "</ul><br />To go back to Info Management, <a href=\"form.php\">click here</a>."; } else { echo "Nothing has been changed<a href=\"form.php\">Click here</a> To go back to Info Management."; }?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 ok does that page display what is changed ? does it work? Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted January 21, 2007 Author Share Posted January 21, 2007 yessiree it does, and quite fine I may add :D[code]<?php // At the very bottom I have the output fields for showing users their mysql datasession_start(); header("Cache-Control: no-cache, must-revalidate"); if (!$_SESSION['id']) { echo "You're not logged in!"; include("doh.html"); exit(); } ?> <html><head> <title>Change Profile Info</title> </head><body> <h1>Change Profile Info</h1> <p>Fill out only the fields you'd like to change:</p> <form action="parse.php" method="post"> Artist Name: <input type="text" name="artname" size="20"><br />Country: <input type="text" name="country" size="20"><br />Province/State: <input type="text" name="province" size="20"><br />city: <input type="text" name="city" size="20"><br />Bio: <textarea rows="5" cols="40" name="bio"></textarea><br />Influences: <textarea rows="5" cols="40" name="infl"></textarea><br /> <input type="submit" value="Update Profile" name="submit"><input type="reset" value="Reset Entries" name="reset"></form> <br><br><br><? print '<textarea rows="1" cols="40" name="bio" >' . $_SESSION['name'] . '</textarea><br>';?><? print '<textarea rows="1" cols="40" name="bio" >' . $_SESSION['country'] . '</textarea><br>';?><? print '<textarea rows="1" cols="40" name="bio" >' . $_SESSION['province'] . '</textarea><br>';?><? print '<textarea rows="1" cols="40" name="bio" >' . $_SESSION['city'] . '</textarea><br>';?><? print '<textarea rows="12" cols="40" name="bio" >' . $_SESSION['bio'] . '</textarea><br>';?><? print '<textarea rows="12" cols="40" name="bio" >' . $_SESSION['infl'] . '</textarea><br>';?></body></html> [/code] Quote Link to comment Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 hehe :)ok so you want these to be shown on form.php when they click the link that says "click here"? Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted January 21, 2007 Author Share Posted January 21, 2007 yep sorry just posted it up there, teeheeAnd 'infoparse.php" and "parse.php" are one and the same, my bad. it all works Quote Link to comment Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 ok on the form.php dont use sessions, unless theres a specific reason why you want to, like keeping the values over many pages, u can use $GET on the link back to form.php make it like this...[code]echo "</ul><br />To go back to Info Management, <a href=\"form.php?cartname=$cartname&ccountry=$ccountry&cprovince=$cprovince&ccity=$ccity\">click here</a>."; [/code]etc... and then do an if (isset(...to show if they have changed Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted January 21, 2007 Author Share Posted January 21, 2007 Thanks Ill give it a shot, That was fast! :D Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted January 21, 2007 Author Share Posted January 21, 2007 OK, I had a couple of bad variables set in my login script. But when i set it all up like you said and fixed my variables, works beautifully.Thank you inztinkt Quote Link to comment Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 anytime, set as solved, and have a nice day :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.