Results 1 to 4 of 4

Thread: Assigning Vars

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    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>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    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.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width