Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    undefined variable problem

    i've came up with the following script for an 'easy' write to file from form page.

    i've done it a few times before with success, but for some strange reason this time i'm having a bit of trouble with the variable 'page' coming up undefined. It's probably something really simple but i can't seem to be able to spot it.

    PHP Code:
        if (isset($_POST['update'])){

            
    $file fopen('db/pages/home.php''a'1);
            
    fwrite($file$page);
            
    fclose($file);
            }
        
        else {  
            
    $lines file('db/pages/home.php');
            
    $l_count count($lines);
            for(
    $x 0$x$l_count$x++)
            {
            }
            echo 
    "<form method=\"post\" name=\"update\" enctype=\"multipart/form-data\" action=\"?page=admin&mode=edit\">";
            echo 
    "<textarea name=\"page\" cols=\"80\" rows=\"8\">".$lines[5]."</textarea>";
            echo 
    "<input type=\"Submit\" name=\"update\" value=\"Update\"></form>";}


    Any help would be greatly appreciated, thanks.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    If I had to guess I would say the "register_globals" PHP flag has been disabled on your PHP server. This "register_globals", when it's turned on, automatically assigns all the $_POST array elements (and $_GET elements) to non-array variables (i.e. the value in $_POST['page'] is assigned to $page). It's been an infamous security hole in PHP and because of that it defaults to "off" in PHP versions 4.3+.

    To be safe and cross-server operational you should just use the $_POST['page'] variable, or manually assign $_POST['page'] to $page (and other form variables) at the beginning of your script.

  • Users who have thanked Fumigator for this post:

    crewebiker (09-05-2007)

  • #3
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    register_globals, agreed. A form input or url name/value pair called 'page' is registering as the var $page when register_globals = On.

    If it's a post, then:

    $page = (!empty($_POST['page'])) ? $_POST['page'] : NULL;

    will fix it, else:

    $page = (!empty($_GET['page'])) ? $_GET['page'] : NULL;
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • Users who have thanked meth for this post:

    crewebiker (09-05-2007)

  • #4
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks guy, that's done the trick, now just another thing...

    would i be able to get '$page' to only write to a specific line in '$file'?

    tried using the same kinda way from the read script but can't quite get it, it comes up with 'fwrite(): supplied argument is not a valid stream resource in...'

    again, help would be greatly appreciated.

    thanks.

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You have to open the file in read/write mode and read each line in until you get to the line you want to overwrite and then write it.


  •  

    Posting Permissions

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