Problem getting variables in URL

index.php:

<? echo "test is: $test"; ?>

If I call the page via:
http://myhost/index.php?test=hey

Shouldn't it return:
test is: hey

All I get is:
test is:

Is something wrong with my installation? If so, what can I do to fix this?
polaughlinAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TimelibConnect With a Mentor Commented:
Another test to try is the longer version of the code:

echo "Test is: " . $HTTP_GET_VARS["test"];

---

If that doesn't work, I'm not sure, but the follow section in your php.ini configures how your server reads it session, post, get, etc. variables.

This should be your default settings, make sure they are.

;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;
;
; Note - track_vars is ALWAYS enabled as of PHP 4.0.3

; The separator used in PHP generated URLs to separate arguments.
; Default is "&".
;arg_separator.output = "&amp;"

; List of separator(s) used by PHP to parse input URLs into variables.
; Default is "&".
; NOTE: Every character in this directive is considered as separator!
;arg_separator.input = ";&"

; This directive describes the order in which PHP registers GET, POST, Cookie,
; Environment and Built-in variables (G, P, C, E & S respectively, often
; referred to as EGPCS or GPC).  Registration is done from left to right, newer
; values override older values.
variables_order = "EGPCS"

; Whether or not to register the EGPCS variables as global variables.  You may
; want to turn this off if you don't want to clutter your scripts' global scope
; with user data.  This makes most sense when coupled with track_vars - in which
; case you can access all of the GPC variables through the $HTTP_*_VARS[],
; variables.
;
; You should do your best to write your scripts so that they do not require
; register_globals to be on;  Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = On

; This directive tells PHP whether to declare the argv&argc variables (that
; would contain the GET information).  If you don't use these variables, you
; should turn it off for increased performance.
register_argc_argv = On

; Maximum size of POST data that PHP will accept.
post_max_size = 8M

; This directive is deprecated.  Use variables_order instead.
gpc_order = "GPC"
0
 
TimelibCommented:
I've done the same code, but not in a echo command.

I usually put it into a variable, then echo or use it.

$TestVar = "Test is: $test";
echo $TestVar;

However, try to this to make sure you are passing URL GET variables.

echo "Test is:" . $test;

Should work, I use it all the time.
0
 
polaughlinAuthor Commented:
Does not work.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
polaughlinAuthor Commented:
Does not work.
0
 
polaughlinAuthor Commented:
Alright.  Register_globals in php.ini was set to Off.  

Changing it to On fixed the problem.  Is there something seriously wrong with changing this to On?

Thanks for your help.
0
 
polaughlinAuthor Commented:
I'd appreciate an answer to my last question.  Here's some more points.
0
 
majorspankCommented:
The following link gives a decent opinion on why register_globals should be Off.

http://www.securiteam.com/securityreviews/6P00G2A3FG.html
0
 
polaughlinAuthor Commented:
Very informative.  I totally understand now.  Sorry I can't give you any points, majorspank.
0
All Courses

From novice to tech pro — start learning today.