#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Predefined Variables and Newer Versions of PHP


    I have a small website that was created in PHP prior to PHP 4.2.0 and the site runs fine on a web server where the Predefined Variables have been enabled, but in a web server running PHP 4.2.0 or greater if the Predefined Variables are disabled my site will not run.

    I would like to modify the code to where my site will run on a newer server running the latest version of PHP.

    Here is an example of some code from my site that I would really appreciate someone to rewrite so it will run on a server with Predefined Variables disabled:

    Sample Code:

    if ($_POST['Submit']) {

    // trim white space from each field
    $_POST['first_name'] = trim($_POST['first_name']);
    $_POST['last_name'] = trim($_POST['last_name']);
    $_POST['email'] = trim($_POST['email']);
    $_POST['username'] = trim($_POST['username']);
    $_POST['password'] = trim($_POST['password']);

    // check for invalid characters/length //only add to this section if you want to check for NULL value!
    if (!check_field($_POST['first_name'])
    || !check_field($_POST['last_name'])
    || !check_field($_POST['email'])
    || !check_field($_POST['username'])
    || !check_field($_POST['password'])) {

    $_SESSION['system_message'] = "<span class=\"errMsg\">Error. Required fields missing!</span>";

    } else {

    // get client data from database
    $qid = db_query("select * from customer limit 1");
    if (!db_num_rows($qid)) {

    $_SESSION['system_message'] = "<span class=\"errMsg\">Error. No client data found!</span>";

    } else {

    $comment = "";
    $password_1 = ($_POST['password']);
    $password_2 = ($_POST['password2']);

    End of Sample Code

    The code above is not complete, but if someone can demonstrate the new way to code what is there so I can understand the new way of coding I would really appreciate the help...

    Ed
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    I guess with "predefined variables" you mean register_globals?

    Apart from that, I'm not sure what you expect from us. Obviously you've already found out how modern application access POST values: they take them from the $_POST array. That's all.

    If there's another problem like a particular error message, tell us what it is.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Register Globals (sorry)


    Originally Posted by Jacques1
    Hi,

    I guess with "predefined variables" you mean register_globals?

    Apart from that, I'm not sure what you expect from us. Obviously you've already found out how modern application access POST values: they take them from the $_POST array. That's all.

    If there's another problem like a particular error message, tell us what it is.
    I asked in my post if someone could rewrite what was there so I can review and get a better idea on how to do what is there with out using register globals (can you help)?
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    The code you posted is already written to work without using register globals. So either:
    1. The problematic piece of code isn't the one you posted
    2. You didn't mean register globals by 'predefined variables'

    I suspect the first.

    Basically, to not use registered globals, when you have something like this:
    Code:
    <input type="text" name="varname" />
    Instead of getting the value like this:
    PHP Code:
    $varname 
    You get the value like this:
    PHP Code:
    $_POST['varname'
    (assuming the form was posted; if you used GET, then use $_GET instead of $_POST)
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    If you're trying to get your code to work with PHP 4.2.0 then give up and get your code working with php 5.2 (at least), we're now on 5.4.x and there have been a lot of changes

    FYI PHP 4.2 reached it's "end of life" over 10 years ago. See the PHP EOL page
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo