473,387 Members | 1,520 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,387 software developers and data experts.

post variables always undefined

Hi folks,
I seem to be using these newsgroups a good bit and probabely will be for the
next three or so months.

I wonder if there is a workaround to a problem I'm having. PHP always says
that variables are undefined for the first time I visit a page. I have
register_globals on and on the second visit a page when a certain post
variable 'has' a value and been defined.

Here's a bit of code I'm working with now.

<?php
if($deleteFlag=="yes") {unlink($filename);
echo "$filename successfully deleted";}
else
{
echo "<table><tr bgcolor='#FFFF00' align=center><td><b>Are you sure you want
to delete &quot;$filename&quot;?
<br>This action cannot be undone</b>";
}
?></td></tr><tr align=center><td><form action="delete.php" method="post"
name="delete"><input name="deleteFlag" type="hidden" value="yes" />
<input name="Submit" type="button" value="Confirm" />
<input name="cancel" type="button" value="Cancel"
/></form></td></tr></table>
</td></td></table>

Basically i want to be able to tell the script that the confirm button was
pressed and to actually delete the file

Jul 17 '05 #1
6 1932
On Sun, 19 Dec 2004 20:30:21 -0000, "Dave" <co*****@akamarketing.com> wrote:
I wonder if there is a workaround to a problem I'm having. PHP always says
that variables are undefined for the first time I visit a page. I have
register_globals on
Boo, hiss. You'd be well advised to turn them off.
and on the second visit a page when a certain post
variable 'has' a value and been defined.

Here's a bit of code I'm working with now.

<?php
if($deleteFlag=="yes") {unlink($filename);


This page had better be accessible strictly to trusted users.

To solve the issue you're asking about, check if the variable is set before
comparing it to anything, e.g.:

if (isset($deleteFlag) && $deleteFlag=="yes")

http://uk2.php.net/isset
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Dave wrote:
<input name="Submit" type="button" value="Confirm" />
<input name="cancel" type="button" value="Cancel" [...] Basically i want to be able to tell the script that the confirm
button was pressed and to actually delete the file


In this case, you shouldn't use a control with "button" as the type. This
kind of control can be handled client side only (e.g. with javascript).

If you want to send the cancellation to the server, use a submit control:

<input name="cancel" type="submit" value="Cancel" />

if (isset($_REQUEST['cancel'])) {...}

BTW, I think that you really should consider to use the $_* superglobals
instead of register_globals. Browse the online manual to read about the
advantages.
JW

Jul 17 '05 #3
Dave wrote:
I seem to be using these newsgroups a good bit and probabely will be for the
next three or so months.
Why are you already thinking about leaving us? :-)
I wonder if there is a workaround to a problem I'm having. PHP always says
that variables are undefined for the first time I visit a page.
Use isset() before the variable:

if (isset($variable)) do_something_with($variable);
I have
register_globals on and on the second visit a page when a certain post
variable 'has' a value and been defined.

Here's a bit of code I'm working with now.

<?php
if($deleteFlag=="yes") {unlink($filename);
echo "$filename successfully deleted";}


<snip>

What would happen if I browsed to
yourserver.com/.../delete.php?deleteFlag=yes&filename=index.php

Turn off register_globals
and validate *all* user input.

*NEVER* trust the user!

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #4
Thanks everyone for their replies so far,

What would happen if I browsed to
yourserver.com/.../delete.php?deleteFlag=yes&filename=index.php

I think you know what would happen :-)
I tried that with this one

http://localhost/delete.php?deleteFl...ename=test.txt
and it deleted test.txt

A number of things then in response

How would malicous people know the names of variables and what their use is,
no urls like the one you gave and the one
I gave can ever be seen in the browser bar. There's no way I can hide my
could my php code when I distribute this program is
there? everyone could simply examine the code and then try to break websites
using the system.

I'm only starting on this project now. (it's for a college project for those
that don't know)
I fully plan to implement logins and basically have something like

if session login is good then {process rest of page}else die(not authorized)
passwords would be stored in database, well encrpyted version of them not
actually the plain text ones.

With security this would mean that URL like the above could not be executed
by the right people.
Am I right in saying that?

Also if register_globals is off basically all I have to do to get at a
variable is use $_POST[filename] rather than $filename.
If register_globals is off, is it therefore impossible to do trick URLs like
the two above regardless if loggins are used.

Pedro if you could address as many of these issues as possible, also other
help too.
Thanks to everyone. Only learning and you have all been helpful.
"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.uni-berlin.de...
Dave wrote:
I seem to be using these newsgroups a good bit and probabely will be for the next three or so months.


Why are you already thinking about leaving us? :-)
I wonder if there is a workaround to a problem I'm having. PHP always says that variables are undefined for the first time I visit a page.


Use isset() before the variable:

if (isset($variable)) do_something_with($variable);
I have
register_globals on and on the second visit a page when a certain post
variable 'has' a value and been defined.

Here's a bit of code I'm working with now.

<?php
if($deleteFlag=="yes") {unlink($filename);
echo "$filename successfully deleted";}


<snip>

What would happen if I browsed to
yourserver.com/.../delete.php?deleteFlag=yes&filename=index.php

Turn off register_globals
and validate *all* user input.

*NEVER* trust the user!

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!

Jul 17 '05 #5
I noticed that Message-ID: <cq**********@kermit.esat.net> from Dave
contained the following:

How would malicous people know the names of variables and what their use is,
no urls like the one you gave and the one


Well this one is a giveaway...
<input name="deleteFlag" type="hidden" value="yes" />
--
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 #6
[ Please don't top post ]
[ See http://www.greenend.org.uk/rjk/2000/06/14/quoting.html ]

Dave top-posted:
How would malicous people know the names of variables and what their use is,
no urls like the one you gave and the one
I gave can ever be seen in the browser bar.
URLs hidden in a frame or built with JavaScript are very easy to "find".
Besides most people tend to use the same names for the same things -- it's
just a question of trying them and getting lucky.
There's no way I can hide my
could my php code when I distribute this program is
there? everyone could simply examine the code and then try to break websites
using the system.
No. Under normal circunstances the PHP code is not visible to anyone
browsing your site.
But that is not enough to stop malicious people from taking guesses to
URL parameters, form submissions, cookie entries, ...
With security this would mean that URL like the above could not be executed
by the right people.
Am I right in saying that?
Basically yes. Without seeing some code we can't tell for sure. Many,
many things could go wrong.
Also if register_globals is off basically all I have to do to get at a
variable is use $_POST[filename] rather than $filename.
Yes.
If register_globals is off, is it therefore impossible to do trick URLs like
the two above regardless if loggins are used.


Nope :-) Even with register_globals off many, many things could go
wrong.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #7

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

Similar topics

13
by: Marcus | last post by:
Hi All, I was wondering if there is a way to ensure that when submitting forms and using POST vars, the page sending the form resides on the same server as the destination page specified in the...
4
by: Daniel | last post by:
Hullo =) Inspired by another guy's questions here I've created an isset function that works (almost) like the one in native PHP: function isset(variablename) {...
8
by: jose luis fernandez diaz | last post by:
Hi, I am reading Stroustrup's book 'C++ Programming Language'. In the 10.4.9 section (Nonlocal Store) he says: "A variable defined outside any function (that is global, namespace, and class...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
6
by: RFS666 | last post by:
Hello, After I posted yesterday "using C# class in jscript", I have a new problem: I have a C# class - DBResult - that contains (and other variables) a string array (and other variables), that...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
107
by: DaveC | last post by:
I always used to initialise variables at declaration, then a couple of colleagues started telling me it was bad practice and that the compiler should be left to spot the use of uninitilised...
18
by: Spoon | last post by:
Hello everyone, I suppose using uninitialized automatic integer variables leads to undefined behavior? i.e. int foo(void) { int bar; /* bar may be 0, or it may be non-0 */
5
Atli
by: Atli | last post by:
Hi everybody. After years of C# and PHP, I'm finally returning to Java. My goal is to create a Java program capable of sending images to a PHP Photo Album on my web server. Right now, however,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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...

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.