Jump to content

Helping rigging a function to work for me


alwaysinit

Recommended Posts

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]
<?php

session_start();

// Some simple code etc etc
$requested_logout = true;

if ($requested_logout) {
   session_restart();
}

// Now the session_id will be different every browser refresh
print(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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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 data
session_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]
Link to comment
Share on other sites

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
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.