Is there a setting to allow $var = "" when POST and GET vars are strict?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keiron Waites

    Is there a setting to allow $var = "" when POST and GET vars are strict?

    I have the following problem: $_POST["val"] and $_GET["val"] variables can
    only be used when in the correct format (not $val), but when I define a
    variable within my PHP page (eg $internal_var = "value" ) it doesn't work
    and is not found. Why is this?

    I have this code in an Apache .htaccess file:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILEN AME} !-f
    RewriteCond %{REQUEST_FILEN AME} !-d
    RewriteRule (.*) /ShareMonkey.net/Web/index.php
    </IfModule>

    Do I need to add some extra code to allow for internal variables?

    TIA


  • sam

    #2
    Re: Is there a setting to allow $var = &quot;&quot; when POST and GET vars are strict?

    "Keiron Waites" <webmaster@-NOSPAM-sharemonkey.com > wrote in message
    news:bleeki$bna $1@hercules.bti nternet.com...[color=blue]
    > I have the following problem: $_POST["val"] and $_GET["val"] variables can
    > only be used when in the correct format (not $val), but[/color]


    You have in your php.ini file register_global s = off
    That's why you can use $_GET['val'] , $_POST['val'] but not $val
    [color=blue]
    > when I define a variable within my PHP page (eg $internal_var = "value" )
    > it doesn't work and is not found. Why is this?[/color]

    All user_defined variables are visible only within the scope
    they are defined in.
    To use them within another scope use the 'global' directive:

    Ex:
    $my_var = "blabala";

    function getIt()
    {
    echo $my_var; // this will print nothing
    // because $my_var is invisible
    // here
    }

    To make the function works:

    function getIt()
    {
    global $my_var; // import $my_var in this scope

    echo $my_var; // this will print 'blabala'
    }

    HTH.
    [color=blue]
    > I have this code in an Apache .htaccess file:
    >
    > <IfModule mod_rewrite.c>
    > RewriteEngine On
    > RewriteBase /
    > RewriteCond %{REQUEST_FILEN AME} !-f
    > RewriteCond %{REQUEST_FILEN AME} !-d
    > RewriteRule (.*) /ShareMonkey.net/Web/index.php
    > </IfModule>
    >
    > Do I need to add some extra code to allow for internal variables?
    >
    > TIA
    >
    >[/color]


    Comment

    Working...