473,419 Members | 4,382 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,419 software developers and data experts.

isset(), empty(), $_GET and $_POST problem

Dan
I was trying to troubleshoot a login page that doesn't work - it keeps
saying the login/password is missing - when my tracing discovered this
peculiar behavior.

register_globals is off, so at the top of my script I assign a few
variables to incoming GET and POST values.

$login = clean($_POST['login'], 30);
$passwd = clean($_POST['passwd'], 30);

$message = $_GET['message'];

clean() is simply a function that trims to the specified length and
applies EscapeShellCmd().

Now, below that I have an if statement to check for whether a
login/password has been supplied or if an error message exists.

if (isset($message) || empty($login) || empty($passwd))
{
// render the html page showing the form
} else {
// do some php/mysql stuff and redirect to another page
}

Yet when I fill out those form fields and submit, it always redisplays
the form with my tracing errors stating that those fields are empty.

When I echo out all $_GET and $_POST variables, indeed they are empty,
and strangely there is a $_GET['message'] that has no value, but
nevertheless is on the end of the url. (/index.php?message=) I can't
figure out how it got there. The form action is just "index.php" and
it uses the POST method, so what could be adding that GET variable?

Now here's the weird part. If I simply add "1 ||" to the beginning of
that if statement, so basically it will always evaluate to true, then
suddenly the $_POST['login'] and $_POST['passwd'] are properly defined
and $_GET['message'] goes away!

So this makes me wonder, are the isset() and empty() functions
actually modifying the variables passed to them somehow? And when I
put a true value in front of them, the if statement stops parsing
before it gets to those functions?
Jul 17 '05 #1
7 11850
Dan
On Sun, 25 Jul 2004 19:12:10 GMT, Dan <ag***@thwackspam.fathom.org>
wrote:
So this makes me wonder, are the isset() and empty() functions
actually modifying the variables passed to them somehow? And when I
put a true value in front of them, the if statement stops parsing
before it gets to those functions?


Well I just disproved that part by putting "|| 1" on the end of the if
statement instead of at the beginning. So now I'm even more baffled.

What could be causing this?
Jul 17 '05 #2
"Dan" <ag***@thwackspam.fathom.org> wrote in message
news:5c********************************@4ax.com...
I was trying to troubleshoot a login page that doesn't work - it keeps
saying the login/password is missing - when my tracing discovered this
peculiar behavior.

register_globals is off, so at the top of my script I assign a few
variables to incoming GET and POST values.

$login = clean($_POST['login'], 30);
$passwd = clean($_POST['passwd'], 30);

$message = $_GET['message'];

clean() is simply a function that trims to the specified length and
applies EscapeShellCmd().

Now, below that I have an if statement to check for whether a
login/password has been supplied or if an error message exists.

if (isset($message) || empty($login) || empty($passwd))
{
// render the html page showing the form
} else {
// do some php/mysql stuff and redirect to another page
}

Yet when I fill out those form fields and submit, it always redisplays
the form with my tracing errors stating that those fields are empty.

When I echo out all $_GET and $_POST variables, indeed they are empty,
and strangely there is a $_GET['message'] that has no value, but
nevertheless is on the end of the url. (/index.php?message=) I can't
figure out how it got there. The form action is just "index.php" and
it uses the POST method, so what could be adding that GET variable?

Now here's the weird part. If I simply add "1 ||" to the beginning of
that if statement, so basically it will always evaluate to true, then
suddenly the $_POST['login'] and $_POST['passwd'] are properly defined
and $_GET['message'] goes away!

So this makes me wonder, are the isset() and empty() functions
actually modifying the variables passed to them somehow? And when I
put a true value in front of them, the if statement stops parsing
before it gets to those functions?


Bet you a banana cupcake that your HTML is screwed up.
--
Obey the Clown - http://www.conradish.net/bobo/
Jul 17 '05 #3
Chung Leong wrote:
"Dan" <ag***@thwackspam.fathom.org> wrote in message
news:5c********************************@4ax.com...
I was trying to troubleshoot a login page that doesn't work - it keeps
saying the login/password is missing - when my tracing discovered this
peculiar behavior.

register_globals is off, so at the top of my script I assign a few
variables to incoming GET and POST values.

$login = clean($_POST['login'], 30);
$passwd = clean($_POST['passwd'], 30);

$message = $_GET['message'];

clean() is simply a function that trims to the specified length and
applies EscapeShellCmd().

Now, below that I have an if statement to check for whether a
login/password has been supplied or if an error message exists.

if (isset($message) || empty($login) || empty($passwd))
{
// render the html page showing the form
} else {
// do some php/mysql stuff and redirect to another page
}

Yet when I fill out those form fields and submit, it always redisplays
the form with my tracing errors stating that those fields are empty.

When I echo out all $_GET and $_POST variables, indeed they are empty,
and strangely there is a $_GET['message'] that has no value, but
nevertheless is on the end of the url. (/index.php?message=) I can't
figure out how it got there. The form action is just "index.php" and
it uses the POST method, so what could be adding that GET variable?

Now here's the weird part. If I simply add "1 ||" to the beginning of
that if statement, so basically it will always evaluate to true, then
suddenly the $_POST['login'] and $_POST['passwd'] are properly defined
and $_GET['message'] goes away!

So this makes me wonder, are the isset() and empty() functions
actually modifying the variables passed to them somehow? And when I
put a true value in front of them, the if statement stops parsing
before it gets to those functions?

Bet you a banana cupcake that your HTML is screwed up.


and how exactly are you sending both a _GET and _POST at the same time. A form
action can be EITHER GET or POST but not both. show us the complete <form> tag.

if you are POSTing your login/pass with a message then shouldn't you be looking
for _POST['message'] not _GET['message']
--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #4
Dan
On Mon, 26 Jul 2004 02:32:34 GMT, Michael Austin
<ma*****@firstdbasource.com> wrote:
Chung Leong wrote:
"Dan" <ag***@thwackspam.fathom.org> wrote in message
news:5c********************************@4ax.com...
I was trying to troubleshoot a login page that doesn't work - it keeps
saying the login/password is missing - when my tracing discovered this
peculiar behavior.

register_globals is off, so at the top of my script I assign a few
variables to incoming GET and POST values.

$login = clean($_POST['login'], 30);
$passwd = clean($_POST['passwd'], 30);

$message = $_GET['message'];

clean() is simply a function that trims to the specified length and
applies EscapeShellCmd().

Now, below that I have an if statement to check for whether a
login/password has been supplied or if an error message exists.

if (isset($message) || empty($login) || empty($passwd))
{
// render the html page showing the form
} else {
// do some php/mysql stuff and redirect to another page
}

Yet when I fill out those form fields and submit, it always redisplays
the form with my tracing errors stating that those fields are empty.

When I echo out all $_GET and $_POST variables, indeed they are empty,
and strangely there is a $_GET['message'] that has no value, but
nevertheless is on the end of the url. (/index.php?message=) I can't
figure out how it got there. The form action is just "index.php" and
it uses the POST method, so what could be adding that GET variable?

Now here's the weird part. If I simply add "1 ||" to the beginning of
that if statement, so basically it will always evaluate to true, then
suddenly the $_POST['login'] and $_POST['passwd'] are properly defined
and $_GET['message'] goes away!

So this makes me wonder, are the isset() and empty() functions
actually modifying the variables passed to them somehow? And when I
put a true value in front of them, the if statement stops parsing
before it gets to those functions?

Bet you a banana cupcake that your HTML is screwed up.


and how exactly are you sending both a _GET and _POST at the same time. A form
action can be EITHER GET or POST but not both. show us the complete <form> tag.

if you are POSTing your login/pass with a message then shouldn't you be looking
for _POST['message'] not _GET['message']


First let me say I've solved the problem. Some code in an included
php file looked like this:

if (!isset($_SESSION['user']))
// redirect to the login page
$message = "There was a problem logging in.";
header("Location: index.php?message=" . urlencode($message));

Originally, the if statement was only followed by a single statement,
and as such, it was not enclosed in code block {brackets}. A second
line was later added, but I didn't notice the brackets were missing.
(I was modifying code that wasn't mine. I would only leave out the
brackets if the entire if statement is all on one line to avoid
exactly this confusion.) As a result, the second line was executed
because it's outside of the control structure, but the first line was
not. (And since my login code was otherwise working, the if always
evaluated to false and left $message undefined.)

To answer the question about sending both _GET and _POST at the same
time, it's possible. If the form uses the POST method, but the action
includes ?var=value stuff in the url, you get both.

However, in my case, I wasn't trying to do that, which is why I was
confused as to where the _GET message was coming from. I also
couldn't figure out where my POST login/password values were
disappearing to. Alas, all the code I was messing with and putting
trace calls into was working fine all along, and it was this included
file that was redirecting with the empty ?message=.

Since this was not screwed up HTML, I believe someone owes me a banana
cupcake. :)

$cupcake = irradiate($_GET['cupcake']); //just to be safe ;)
Jul 17 '05 #5
On Mon, 26 Jul 2004 02:32:34 GMT
Michael Austin <ma*****@firstdbasource.com> wrote:

[snipt]

and how exactly are you sending both a _GET and _POST at the same
time. A form action can be EITHER GET or POST but not both. show us
the complete <form> tag.


Uhm... I suggest you think again, or try this.

<?php
// Please bare with syntax-errors... I've been coding Ruby
// the last 20 hours...

if (!empty($_POST['submit'])) {
echo "<pre>";
echo "PHP says: REQUEST_METHOD: " . $_SERVER['REQUEST_METHOD'];
echo "\n\nBut we get:"

echo "\n\n_POST: ";
print_r($_POST);

echo "\n\n_GET: ";
print_r($_GET);
echo "</pre>";
}

$self = $_SERVER['PHP_SELF'];
print <<<EOHTML
<form action="$self?what=you_see&aaand=this" method="POST" />
<input type="text" name="something" value="type something and submit"
/><br />
<input type="submit" name="submit" value=" Submit it! " />
</form>
EOHTML
?>

Might enlighten you a little. ;)

Best regards,
Madsen

--
Anders K. Madsen --- http://lillesvin.linux.dk

"There are 10 types of people in the world.
Those who understand binary - and those who don't."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBBUSNlNHJe/JASHcRAgw3AJ0X204q0/hiKw5+NSTVj38o6jl6bQCfVRUG
R3wXw56MCoCOynKVwu0SSH8=
=PbuL
-----END PGP SIGNATURE-----

Jul 17 '05 #6
"Dan" <ag***@thwackspam.fathom.org> wrote in message
news:nn********************************@4ax.com...

Since this was not screwed up HTML, I believe someone owes me a banana
cupcake. :)

$cupcake = irradiate($_GET['cupcake']); //just to be safe ;)


[) <- there!
--
Obey the Clown - http://www.conradish.net/bobo/

Jul 17 '05 #7
I noticed that Message-ID: <jf********************@comcast.com> from
Chung Leong contained the following:
$cupcake = irradiate($_GET['cupcake']); //just to be safe ;)


[) <- there!


It's a bit small. You should have made it a class so that he could have
as many instances as he wants. :)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

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

Similar topics

8
by: Yannick Turgeon | last post by:
Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem we've got is that our PHP applications generate errors saying that...
4
by: Kevin | last post by:
I am having problems in my php code. I am relatively new to php but I know some basics. This is the problem: when i try to echo some information that is typed into form back to the screen i...
5
by: lorenzdominic_ | last post by:
Hi Recently I have been developing a form that uses the _POST variable. Today the _POST variable was empty everytime I submitted my form however I changed the post method to be GET and the...
9
by: wouter | last post by:
hey hi..... I wanna make a switch wich does this: if pagid is set do A, if catid is set do B, if projectid is set do C, else do D. So i was thinking something like this:
2
by: sathyashrayan | last post by:
Dear group, My question may be novice. I have seen codes where the isset() is used to test weather a user's session ($_SESSION) is set before entering a page. A kind of direct access to a page is...
2
by: Adam Baker | last post by:
I'm not sure whether the following is a problem with PHP or my Apache server. Minimal example: <?php if (isset($dummy)) echo "Set."; else echo "Not set."; echo...
8
by: Simon Dean | last post by:
Im taking Im doing something stupid here? I thought it was clever... just learned a little more about isset. $a = (isset($_GET)) ? $_GET : (isset($_POST)) ? $_POST : ""; I guess you can see...
10
by: major | last post by:
The following code processes a blank field as though it has some value and proceeds as though it was set to some value. Apparently isset() is not working, because it thinks that a blank text...
2
by: Bill H | last post by:
I have gotten into the habit of using isset for every $_POST variable, checking that it is set before I even check to see if it contains anything. For example: if (isset($_POST) && $_POST != "")...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.