Jump to content

Clearing post values after use


slpctrl

Recommended Posts

<?php
function clean ($var)
{
   return htmlspecialchars($var);
   return stripslashes($var);
}

include("main.html");
$user=clean($_POST['nick']);
$message=clean($_POST['text']);
if(isset($user) && isset($message) && !empty($user) && !empty($message))
{
   $stuff="<font color=\"#00FF00\"><b>$user: </font></b><font color=\"#FFFFFF\">$message</font><br>\n";
   $file=fopen("chat.html","a");
   fwrite($file, $stuff);
   fclose($file);
}
else
die();
?>

 

Here's my PHP code, the main.html isn't really important it just has an iframe with the chat HTML screen, and an input for a nick and message. But when you refresh it, it reposts. How do I prevent this from happening?

Link to comment
https://forums.phpfreaks.com/topic/104612-clearing-post-values-after-use/
Share on other sites

Whoops, never mind I got it. Just added the HTML to the PHP:

 

<html>
<head>
<title>Chat Box</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<br><br><br><br><br><br><br><br><br>
<H1>Chat Box</H1>
<iframe src="chat.html" width="700" height="250"></iframe>
<br>
<br>
<form name="input" action="chat.php" method="post" target="_self">
Nick:<br><input type="text" name="nick"><br>
Message:<br><input type="text" name="text"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</center>
</html>
<?php
function clean ($var)
{
   return htmlspecialchars($var);
   return stripslashes($var);
}

$user=clean($_POST['nick']);
$message=clean($_POST['text']);
if(isset($user) && isset($message) && !empty($user) && !empty($message))
{
   $stuff="<font color=\"#00FF00\"><b>$user: </font></b><font color=\"#FFFFFF\">$message</font><br>\n";
   $file=fopen("chat.html","a");
   fwrite($file, $stuff);
   fclose($file);
   header('location: ./chat.php');
}
else
die();
?>

 

:D

<?php
function clean ($var)
{
  return htmlspecialchars($var);
  return stripslashes($var);
}

$user=clean($_POST['nick']);
$message=clean($_POST['text']);
if(isset($user) && isset($message) && !empty($user) && !empty($message))
{
  $stuff="<font color=\"#00FF00\"><b>$user: </font></b><font color=\"#FFFFFF\">$message</font><br>\n";
  $file=fopen("chat.html","a");
  fwrite($file, $stuff);
  fclose($file);
  header('location: '.$_SERVER['REQUEST_URI']);
  exit;
}
?>
<html>
<head>
<title>Chat Box</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<br><br><br><br><br><br><br><br><br>
<H1>Chat Box</H1>
<iframe src="chat.html" width="700" height="250"></iframe>
<br>
<br>
<form name="input" method="post">
Nick:<br><input type="text" name="nick"><br>
Message:<br><input type="text" name="text"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</center>
</html>

Okay, I got all that. Now how do I take this:

 

<html>
<head>
<title>Chat Box</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<br><br><br><br><br><br><br><br><br>
<H1>Chat Box</H1>
<iframe src="chat.html" width="700" height="250"></iframe>
<br>
<br>
<form name="input" action="chat.php" method="post" target="_self">
Nick:<br><input type="text" name="nick"><br>
Message:<br><textarea name="text" cols="30" rows="5"></textarea><br><br>
<input type="submit" name="submit" value="submit">
</form>
</center>
</html>
<?php
function clean ($var)
{
   return htmlspecialchars($var);
   return stripslashes($var);
}
if($_POST['nick'] && $_POST['text'])
{
   $user = clean($_POST['nick']);
   $message=clean($_POST['text']);
   $stuff="<font color=\"#00FF00\"><b>$user: </font></b><font color=\"#FFFFFF\">$message</font><br>\n";
   $file=fopen("chat.html","a");
   fwrite($file, $stuff);
   fclose($file);
   header('Location: chat.php');
}
?>

 

And make the iframe scroll to the bottom???

Archived

This topic is now archived and is closed to further replies.

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