Improve company productivity with a Business Account.Sign Up

x
?
Solved

Problem getting variables in URL

Posted on 2002-07-29
8
Medium Priority
?
302 Views
Last Modified: 2008-03-06
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?
0
Comment
Question by:polaughlin
  • 5
  • 2
8 Comments
 
LVL 1

Expert Comment

by:Timelib
ID: 7186193
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
 

Author Comment

by:polaughlin
ID: 7186207
Does not work.
0
 

Author Comment

by:polaughlin
ID: 7186214
Does not work.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 1

Accepted Solution

by:
Timelib earned 2000 total points
ID: 7186312
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
 

Author Comment

by:polaughlin
ID: 7186353
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
 

Author Comment

by:polaughlin
ID: 7186469
I'd appreciate an answer to my last question.  Here's some more points.
0
 
LVL 1

Expert Comment

by:majorspank
ID: 7186660
The following link gives a decent opinion on why register_globals should be Off.

http://www.securiteam.com/securityreviews/6P00G2A3FG.html
0
 

Author Comment

by:polaughlin
ID: 7187022
Very informative.  I totally understand now.  Sorry I can't give you any points, majorspank.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question