473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

variable handling - new user problem

Hi all,
I am a new php learner. I have Fecora Core 1 with apache2 and php
installed on 1 pc and SuSE 9 with apache2 and php installed on a laptop.
I have the following problem with both:

I have a simple form: 1 field
I submit with action=get and the value is passed.
When the form refreshes the variable will NOT show with
echo $username;

However if I set $username to a value explicityly it will print it.
This suggests that the variable value is not being passed from form to
form. Otherwise php seems to be working.

All help and ideas appreciated.

TIA

Bob Hartung

Jul 17 '05 #1
3 1600
Bob Hartung <rw****@netexpress.net> wrote in
news:bv********@library1.airnews.net:
Hi all,
I am a new php learner. I have Fecora Core 1 with apache2 and php
installed on 1 pc and SuSE 9 with apache2 and php installed on a laptop.
I have the following problem with both:

I have a simple form: 1 field
I submit with action=get and the value is passed.
When the form refreshes the variable will NOT show with
echo $username;

However if I set $username to a value explicityly it will print it.
This suggests that the variable value is not being passed from form to
form. Otherwise php seems to be working.


Older versions of php would automatically create variable names from form
fields. That, however, can create lots of security and maintainability
problems, so current versions don't do it unless you explicitly enable the
register_globals option in php.ini. The preferred way to retrieve values
when using the GET method is $_GET['username'] (if you had been using the
POST method it would have been, surprise surprise, $_POST['username']).

Many books and tutorials, especially if they're more than a few years old,
assume that register_globals is turned on. I'd advise *not* turning it on
at this stage in your learning, in order to avoid developing bad habits.
Jul 17 '05 #2
Eric
Thank you! I also found that $_REQUEST in place of $_GET works the
same. I am sure there are some nuances to this and I'll get to that,
but now I can fumble my way ahead.

And yes, you were correct. I am using an old book on PHP while
awaiting somethins that looks good for PHP5 to hit the streets.
Thanks again,

Bob
Eric Bohlman wrote:
Bob Hartung <rw****@netexpress.net> wrote in
news:bv********@library1.airnews.net:

Hi all,
I am a new php learner. I have Fecora Core 1 with apache2 and php
installed on 1 pc and SuSE 9 with apache2 and php installed on a laptop.
I have the following problem with both:

I have a simple form: 1 field
I submit with action=get and the value is passed.
When the form refreshes the variable will NOT show with
echo $username;

However if I set $username to a value explicityly it will print it.
This suggests that the variable value is not being passed from form to
form. Otherwise php seems to be working.

Older versions of php would automatically create variable names from form
fields. That, however, can create lots of security and maintainability
problems, so current versions don't do it unless you explicitly enable the
register_globals option in php.ini. The preferred way to retrieve values
when using the GET method is $_GET['username'] (if you had been using the
POST method it would have been, surprise surprise, $_POST['username']).

Many books and tutorials, especially if they're more than a few years old,
assume that register_globals is turned on. I'd advise *not* turning it on
at this stage in your learning, in order to avoid developing bad habits.


Jul 17 '05 #3
Bob Hartung <rw****@netexpress.net> wrote in
news:bv********@library2.airnews.net:
Eric
Thank you! I also found that $_REQUEST in place of $_GET works the
same. I am sure there are some nuances to this and I'll get to that,
but now I can fumble my way ahead.


The potential problems there are that, first, there's a configuration
directive (variables_order) that controls which of the Get, Post, and
Cookie values are included in $_REQUEST, and this may be set differently
from server to server. Second, if a cookie value has the same name as a
form value, or if both GET and POST are being used simultaneously (e.g. a
form with method POST and an action URL with fixed query parameters), one
of the values will overwrite the other in $_REQUEST (which one wins is
determined by variables_order).

So using $_REQUEST isn't as reliable as using $_POST, $_GET, and $_COOKIE
because it's more vulnerable to influences beyond your control.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
8
by: atomo | last post by:
Hi, i got a problem with variable handling with mozilla(0.7). These lines of code works fine on IE(6), but they doesn't on Mozilla: echo" function check(){ if( ".$name.".value!=\"\" ) {...
19
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
3
by: mydejamail | last post by:
Is there a major flaw with PHPs variable handling? I am writing some PHP scripts and the variables seem to be all over the place. Eg in one instance, I am counting the number of times a for loop...
6
by: Vyoma | last post by:
This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I have been lurking around at several forums with regard to login and user authentication scripts and...
5
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
9
by: Chad | last post by:
This might be a bit vague and poorly worded..... In my program, I handle function failures using fprintf() and exit() like: fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); There...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.