Find the answer to your Linux question:
Results 1 to 5 of 5
Take some code included in a page (.php) < href="mysite.php?answer=yes">click here</a> Works fine on my windows box (bah!) and on my webhost which is linux, but won't work on my ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Jul 2003
    Location
    Farnborough, UK
    Posts
    1,305

    prob with passing variables in uri


    Take some code included in a page (.php)

    < href="mysite.php?answer=yes">click here</a>

    Works fine on my windows box (bah!) and on my webhost which is linux, but won't work on my rh9 box running the apche/php/mysql set up.

    php stuff like includes work, just this passing of variables. If I put echo ($answer); in the mysite.php it comes up empty.

    Any ideas?

    Ta

  2. #2
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284

    Re: prob with passing variables in uri

    Quote Originally Posted by Chris H
    Take some code included in a page (.php)

    < href="mysite.php?answer=yes">click here</a>

    Works fine on my windows box (bah!) and on my webhost which is linux, but won't work on my rh9 box running the apche/php/mysql set up.

    php stuff like includes work, just this passing of variables. If I put echo ($answer); in the mysite.php it comes up empty.

    Any ideas?

    Ta
    Its to do with global variables.

    $answer will work when globals are turned on, but in the case of your local box, globals in your php.ini are off.

    The correct way to do it is (will work on you box and your Host's):
    Code:
    echo $_GET&#91;'answer'&#93;;

    to expand:
    Url Variables are in $_GET array, server variables are in the $_SERVER array, and form variables are in $_POST array.

    All new install's of PHP will turn globals off by default, as in some cases they can present a security risk, so it is best to program without them.

    Jason

  3. #3
    Linux Engineer Giro's Avatar
    Join Date
    Jul 2003
    Location
    England
    Posts
    1,219
    They are nicer to work with. You should always write scripts using this method. I tend to use the old style if im writting for a client eg.. $HTTP_GET_VARS its more compatible with older version of PHP which dont support super global variables (pre PHP-4.0.1 dosent support super globals eg.. $_GET IIRC). For a full list go here -> http://www.phpfreaks.com/phpmanual/p...redefined.html

  4. #4
    Linux Engineer
    Join Date
    Jul 2003
    Location
    Farnborough, UK
    Posts
    1,305
    Awesome!

    I bow at the feet of Jaguar & Ol man.

    Appreciated. ta. :P

  5. #5
    Linux Engineer
    Join Date
    Jul 2003
    Location
    Farnborough, UK
    Posts
    1,305
    *cough*

    Working now

Posting Permissions

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