473,804 Members | 3,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_global s 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($filena me);
echo "$filename successfully deleted";}
else
{
echo "<table><tr bgcolor='#FFFF0 0' align=center><t d><b>Are you sure you want
to delete &quot;$filename &quot;?
<br>This action cannot be undone</b>";
}
?></td></tr><tr align=center><t d><form action="delete. php" method="post"
name="delete">< input name="deleteFla g" 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 1959
On Sun, 19 Dec 2004 20:30:21 -0000, "Dave" <co*****@akamar keting.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_globa ls 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($filena me);


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($deleteF lag) && $deleteFlag=="y es")

http://uk2.php.net/isset
--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.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($_REQUES T['cancel'])) {...}

BTW, I think that you really should consider to use the $_* superglobals
instead of register_global s. 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($variabl e)) do_something_wi th($variable);
I have
register_global s 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($filena me);
echo "$filename successfully deleted";}


<snip>

What would happen if I browsed to
yourserver.com/.../delete.php?dele teFlag=yes&file name=index.php

Turn off register_global s
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?dele teFlag=yes&file name=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_global s is off basically all I have to do to get at a
variable is use $_POST[filename] rather than $filename.
If register_global s 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($variabl e)) do_something_wi th($variable);
I have
register_global s 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($filena me);
echo "$filename successfully deleted";}


<snip>

What would happen if I browsed to
yourserver.com/.../delete.php?dele teFlag=yes&file name=index.php

Turn off register_global s
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**********@k ermit.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="deleteFla g" 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_global s is off basically all I have to do to get at a
variable is use $_POST[filename] rather than $filename.
Yes.
If register_global s is off, is it therefore impossible to do trick URLs like
the two above regardless if loggins are used.


Nope :-) Even with register_global s 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
1821
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 form action. For example, if I have a page on a live server that accepts POST variables, I can simply create a second page on my local host or any other server for that matter that lets me send any values I want for these POST variables.
4
3615
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) { return(typeof(eval("window."+variablename))!='undefined'); } I use it like if(isset('myVar') { alert(myVar); }
8
2536
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 static variables) is initializated (constructed) before main is invoked . . ." .. . .
122
5353
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) { /* array differs from value, do something*/
6
1857
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 contains data from a database query which is done in C# in codebehind. I create a jscript - script that is injected into the aspx-page. I need this to fill an activeX-control with data. I assign the string-array (and - for testing - a single...
17
3354
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
4180
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 variables and hence possible bugs. Your thoughts on the above would be welcome (as an aside), but my main problem follows. Now I've recently upgraded to gcc 4, and I find I'm missing the compiler warnings I used to get on gcc 3 regarding...
18
1943
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
106360
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, I am stuck trying to send simple text variables through POST to my PHP script. The code does seem to connect to the script like it is supposed to, but it seems unable to send the POST variables. The PHP script is returning a 'Undefined index'...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.