Solved

Problem getting variables in URL

Posted on 2002-07-29
8
240 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
Comment Utility
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
Comment Utility
Does not work.
0
 

Author Comment

by:polaughlin
Comment Utility
Does not work.
0
 
LVL 1

Accepted Solution

by:
Timelib earned 500 total points
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:polaughlin
Comment Utility
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
Comment Utility
I'd appreciate an answer to my last question.  Here's some more points.
0
 
LVL 1

Expert Comment

by:majorspank
Comment Utility
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
Comment Utility
Very informative.  I totally understand now.  Sorry I can't give you any points, majorspank.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 look for a specific file type in a local or remote server directory using PHP.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now