|
-
Feb 3rd, 2008, 09:11 AM
#1
Thread Starter
Member
Assigning Vars
Basically I'm trying something out. What I'm trying to accomplish here, is that when you enter data into the textbox (which has text assigned to it) which you have edited/added to the previous text and echo it off. It does that perfectly, but I'm wanting it too save and stay as that, until you decide to write again, is there anyway of doing this? I was thinking about sessions? But it seems too steep.
PHP Code:
<form method="post" action="test.php" >
<?php $hello = "SOMETEXT"; ?>
<input type="text" name="getme" value="<?php printf($hello); ?>" />
<br>
<?php
$GetMod = $_POST['getme'];
$hello += $GetMod;
echo $GetMod;
?>
<br>
<input type="submit" name="submit" value="submit" />
</form>
-
Feb 3rd, 2008, 11:01 AM
#2
Re: Assigning Vars
It would be wise to htmlspecialchars() before you echo your _POST variable eotherwise your page will be vulnerable to cross site script attacks. Also it would be better dealing with the _POST variable after submission. You can then add the text to the value part of the HTML.
With regards to your problem, the best option is probably a single cookie or a session.
PHP Code:
<?php if (isset($_POST['getme']) { $GetMod = $_POST['getme']; // user htmlspecialchars here $_COOKIE['hello'] = += $GetMod; } else { $_COOKIE['hello'] = 'SOMETEXT'; }
$hello = $_COOKIE['hello']; ?> <form method="post" action="test.php" > <?php $hello = "SOMETEXT"; ?> <input type="text" name="getme" value="<?php printf($hello); ?>" /> <br> <?php echo $GetMod; ?> <br> <input type="submit" name="submit" value="submit" /> </form>
-
Feb 3rd, 2008, 11:11 AM
#3
Thread Starter
Member
Re: Assigning Vars
Thanks, but it doesn't work fully.. Because once you've assigned it it stops there, and if you hit F5 it'll still be there. But if you click go on the toolbar in the brower it's default again.
-
Feb 3rd, 2008, 11:43 AM
#4
Re: Assigning Vars
I am not sure what you mean here. But the page is probably cached by the browser. So you will need to send some anti cahcing headers to prevent this using the header() function (instructions here) or just use sessions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|