Results 1 to 3 of 3

Thread: Strange variable problem *SOLVED*

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Strange variable problem *SOLVED*

    I have a registration form that I've got a check to make sure the 'UserName' field is not left empty. The strange thing is on my local machine the "UserName' variable doesn't get passed through the form but if i test the registration (using exactly the same code) on my website the variable is passed through the form.


    Has anyone come across this before and better yet how to overcome the problem as i don't want to make a change to the code and have to upload the file to make sure it works?

    Thanks.
    PHP Code:
    //This is part of the form
    <form method=\"post\" action=\"index.php?substr=2&act=register\">
    <u>Username</u>: <input type=\"text\" name=\"uname\">
    </form> 

    PHP Code:
    //This checks for the empty field
    if (empty($uname)) {

    echo 
    "<html><head></head><body bgcolor=\"dcdcdc\"><br><br>User Name not entered<br><a href=\"javascript:history.back(1)\">Back</a><br></body></html>";

    exit;


    Last edited by lintz; Aug 21st, 2004 at 03:03 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    This is becuase on one server you have register globals turned on and on the other you don't. Register globals automatically registers all variablees passed to the script though the GET,POST,COOKIE and SESSION as global variables.

    In my opinion regsiter globals should never be on and never be used. Read about the security problems it can cause here:

    http://uk.php.net/register_globals

    To access your variables you need to use the following super global arrays:

    $_POST = Variables passed via the post method.
    $_GET = Variables passed via the GET method - i.e the query strinq
    $_COOKIE = Variables passed from client side cookies.

    So adding the following line to your code will bring it back to life:
    PHP Code:
    $uname $_POST['uname'];

    //This checks for the empty field
    if (empty($uname)) {

    echo 
    "<html><head></head><body bgcolor=\"dcdcdc\"><br><br>User Name not entered<br><a href=\"java script:history.back(1)\">Back</a><br></body></html>";

    exit;


    P.s: To turn off register globals go to your PHP.ini file and change the register_globals directive to:

    register_globals = Off
    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
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Thanks visualAd - I just found the answer as well jsut as I got your reply.

    Thanks again.

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