Jump to content

Killing a $_POST variable


feck

Recommended Posts

I have a page where an output variable display's in the page, when submitted with the form the next page display's the data entered to enable the user to go back and edit any mistakes.Using hidden form fields I'm posting the variable back to the page, but because I would then like to use this $_POST variable instead of the pages variable, I would then once used like to kill this $_POST variable.How do I completly kill a $_POST variable, so the next refresh of the page uses the old variable?I understand the logic of how this can be achieved using if statements but how do I kill this variable, and make it disapear from my machine?So basically my question is this how do you completly kill $_POST variables?

Link to comment
Share on other sites

Does'nt workon post variables that is.Although it does unset any post variable, once the page is refreshed the post variables are reloaded from the browser cache.Anyone out there know a way around this, without doing page redirects?Can PHP be used too flush the browser-cache?

Link to comment
Share on other sites

You can't use PHP for that, but you can make a session which says there was or wasn't a post posted. Before the session expires the browser must be closed first..Something like this:

<?php	session_start ( );		if ( !isset ( $_SESSION [ 'post' ] ) )	{		$_SESSION [ 'post' ] = false;	}	if ( $_SERVER [ 'REQUEST_METHOD' ] == 'POST' && !$_SESSION [ 'post' ] )	{		// Do something				$_SESSION [ 'post' ] = true;	}	else	{		// Form	}	?>

Link to comment
Share on other sites

I have a page where an output variable display's in the page, when submitted with the form the next page display's the data entered to enable the user to go back and edit any mistakes.Using hidden form fields I'm posting the variable back to the page, but because I would then like to use this $_POST variable instead of the pages variable, I would then once used like to kill this $_POST variable.How do I completly kill a $_POST variable, so the next refresh of the page uses the old variable?I understand the logic of how this can be achieved using if statements but how do I kill this variable, and make it disapear from my machine?So basically my question is this how do you completly kill $_POST variables?
That is sort of irrelevant, I think you are confused somewhere. You don't need to delete a $_POST variable, they do not get carried across from page to page. If you have something in $_POST on one page, it's because you put it there. If you don't want a $_POST variable there, then don't put it there.To understand this, you have to think about what the request to the server looks like. It starts with a lot of headers, things like the IP of the person asking for it, what browser they are using, the URL they are asking for, the length of the request, etc. A simple GET request for an image using HTTP 1.1 looks like this:GET /images/logo.gif HTTP/1.1That is the actual "request line", which asks for the resource. After that line are all of the headers, and then a linebreak (empty line), and then the body of the request. A request like the one above for an image, or another simple GET request, would not have a body. A POST request does have a body. The body for a POST request might look like this:var1=value1&var2=value2&var3=value3etc, it is just a line of URL-encoded name/value pairs. That is the information that gets stored in the $_POST array in PHP.So, if you have a variable that was passed through POST on a page, and you don't want it to be there, then the solution is to not pass it through POST in the first place. Your question sounds confusing though, I can't understand what this means:
Using hidden form fields I'm posting the variable back to the page, but because I would then like to use this $_POST variable instead of the pages variable, I would then once used like to kill this $_POST variable.
If you are setting up a preview page, like where someone types out some info, hits preview, they see what they typed, and can either edit or submit it, that's pretty easy. It sounds like you are over-thinking something. First of all, you would want everything on one page, you don't want more then one PHP script to do the entire edit/preview/submit process. You would pass a hidden value to tell the script which action you want it to perform. So it would look something like this:
$page_mode = $_POST['page_mode'];if ($page_mode == "Submit"){  //the page was submitted, save the info or whatever you need to do  ... //database work here  echo "thank you, information was saved";  //or redirect to another page  exit();}if ($page_mode == "Preview"){  echo $_POST['data']; //whatever you want to do for preview  echo "<form action=\"{$_SERVER['SCRIPT_NAME']}\" method=\"post\">";  echo "<input type=\"hidden\" name=\"data\" value=\"" . htmlentities($_POST['data']) . "\">";  echo "<input type=\"submit\" name=\"page_mode\" value=\"Edit\">";  echo "<input type=\"submit\" name=\"page_mode\" value=\"Submit\">";  echo "</form>";}if ($page_mode == "Edit" || $page_mode == ""){  echo "<form action=\"{$_SERVER['SCRIPT_NAME']}\" method=\"post\">";  echo "<textarea name=\"data\">" . $_POST['data'] . "</textarea>";  echo "<input type=\"submit\" name=\"page_mode\" value=\"Preview\">";  echo "</form>";}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...