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

quandry using GET

I have a page that lists a bunch of objects, stored in a database, to
the user. After each object I'd like to do something like:

object1 [edit] [delete]
object2 [edit] [delete]

and so on, where "edit" and "delete" are links. Right now, each link
uses GET to pass the object ID to the scripit that will deal with it.
For example, the urls for the first object links are something like:

edit: http://www.host.com/edit.php?obj=object1
delete: http://www.host.com/delete.php?obj=object1

and similar for the second...you get the idea. This works alright for
the edit option, since it's okay (even advantageous) for a user to
bookmark it. However, it's problematic for the delete option. If a user
bookmarks it, and then tries to visit the site later, they might
unintentionally delete something. I can't use POST since this doesn't
lend itself to a form. I know I could throw some javascript in there to
handle it, but I'm trying to avoid javascript as much as possible.

Does anyone know a better way to do this? Thanks.

Dec 22 '05 #1
5 1227
sw********@yahoo.com wrote:
[...] each link
uses GET to pass the object ID to the scripit that will deal with it.
For example[...]:

edit: http://www.host.com/edit.php?obj=object1
delete: http://www.host.com/delete.php?obj=object1

[...] This works alright for
the edit option, since it's okay (even advantageous) for a user to
bookmark it. However, it's problematic for the delete option. If a user
bookmarks it, and then tries to visit the site later, they might
unintentionally delete something. I can't use POST since this doesn't
lend itself to a form. I know I could throw some javascript in there to
handle it, but I'm trying to avoid javascript as much as possible.

Does anyone know a better way to do this? Thanks.


Can you make delete.php display the object and confirm (with a button)
the deletion?

Dec 22 '05 #2
sw********@yahoo.com wrote:
I have a page that lists a bunch of objects, stored in a database, to
the user. After each object I'd like to do something like:

object1 [edit] [delete]
object2 [edit] [delete]

and so on, where "edit" and "delete" are links. Right now, each link
uses GET to pass the object ID to the scripit that will deal with it.
For example, the urls for the first object links are something like:

edit: http://www.host.com/edit.php?obj=object1
delete: http://www.host.com/delete.php?obj=object1

and similar for the second...you get the idea. This works alright for
the edit option, since it's okay (even advantageous) for a user to
bookmark it. However, it's problematic for the delete option. If a user
bookmarks it, and then tries to visit the site later, they might
unintentionally delete something. I can't use POST since this doesn't
lend itself to a form. I know I could throw some javascript in there to
handle it, but I'm trying to avoid javascript as much as possible.

Does anyone know a better way to do this? Thanks.


You can use POST, so with a form:
<form name="myform" action="action.php" method="POST">

Have two hidden fields:
<input type="hidden" name="act" value="" />
<input type="hidden" name="obj" value="" />

The delete link can then be:
<a href="#" onclick="document.myform.act.value='delete';
document.myform.obj.value='object1'; document.myform.submit(); return
false">Delete</a>

Similarly, the edit link can be:
<a href="#" onclick="document.myform.act.value='edit';
document.myform.obj.value='object1'; document.myform.submit(); return
false">Edit</a>

You then only need one PHP page to handle edit and delete which just
checks $_POST['act'].

I'll actually suggest putting all this javascript in a function (e.g.
doact(act,obj) which returns false) so the link can just be:
<a href="#" onclick="return doact('delete','object1');">Delete</a>

HTH
Robin
Dec 22 '05 #3
Following on from sw********@yahoo.com's message. . .
I have a page that lists a bunch of objects, stored in a database, to
the user. After each object I'd like to do something like:

object1 [edit] [delete]
object2 [edit] [delete]

and so on, where "edit" and "delete" are links. Right now, each link
uses GET to pass the object ID to the scripit that will deal with it.
For example, the urls for the first object links are something like:

edit: http://www.host.com/edit.php?obj=object1
delete: http://www.host.com/delete.php?obj=object1

and similar for the second...you get the idea. This works alright for
the edit option, since it's okay (even advantageous) for a user to
bookmark it. However, it's problematic for the delete option. If a user
bookmarks it, and then tries to visit the site later, they might
unintentionally delete something. I can't use POST since this doesn't
lend itself to a form. I know I could throw some javascript in there to
handle it, but I'm trying to avoid javascript as much as possible.

Does anyone know a better way to do this? Thanks.

So what? If they really _bookmark_ a delete link who cares - what's
going to explode? Obviously delete.php checks lots of things before
doing anything *because it has to trap lots of other abuse anyway*.

ONE of these tests might be to check you've just come from a page where
deleting is 'on the menu'.
# ---------------------------------------------------------------------
function CheckComeFrom($PossibleWaysToGetHere,$Destination= 'pp000.php'){
# This is a security function which chucks the user out
# if the refering page is not one of those supplied in the list
# Returns TRUE if all is OK
#
# Put near the top of a script in a not-if {exit;}
# (The actual jump to the destination will be done in this script but
the exit
# is to tidy up any stack of script execution.)
#
# eg if(!CheckComeFrom('foo.php')){exit;}
#
# Multiple come-froms can be specified by splitting names with a + sign
# eg 'foo.php+bar.php+fox.php'
#
# Destination can be overridden. Suppose you want the remote address
put
# onto a blacklist you could send them to putonblacklist.php
#
# This uses $_SERVER['HTTP_REFERER'] which the documention notes
# may not be completely trustworthy.
# ---------------------------------------------------------------------
$cfrom = CameFrom();
$m = '';
if(!$cfrom){
$m='Not referred from anywhere';
$comefrom=$Destination;
}else{
$pw = strtolower('+'.$PossibleWaysToGetHere.'+');
$hit = strpos($pw,'+'.$cfrom.'+');
$rv = (!($hit===FALSE));
if(!$rv){
// test for reloading page etc which is always allowed
$rv=($cfrom==strtolower(basename($_SERVER['PHP_SELF'])));
}
if(!$rv){$m="From:$cfrom";}
}

if($m){
$m .= "<br>Allowed:$PossibleWaysToGetHere";
MSG('CheckComeFrom failed','',$m,$cfrom); // Standard error message
screen
exit;
}
return $rv;
}
# ---------------------------------------------------------------------
function CameFrom(){
# Return the calling page without any base bits or argument bits
# Return '' if no referring page found
# ---------------------------------------------------------------------
if(!isset($_SERVER['HTTP_REFERER'])){
$rv='';
}else{
$comefromfull = basename(strtolower($_SERVER['HTTP_REFERER']));
$comefrom = explode('?',$comefromfull); // drop any ?foo=bar bits
$rv = $comefrom[0];
}
return $rv;
}
--
PETER FOX Not the same since the bookshop idea was shelved
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Dec 22 '05 #4
sw********@yahoo.com wrote:
I have a page that lists a bunch of objects, stored in a database, to
the user. After each object I'd like to do something like:

object1 [edit] [delete]
object2 [edit] [delete]

and so on, where "edit" and "delete" are links. Right now, each link
uses GET to pass the object ID to the scripit that will deal with it.
For example, the urls for the first object links are something like:

edit: http://www.host.com/edit.php?obj=object1
delete: http://www.host.com/delete.php?obj=object1

and similar for the second...you get the idea. This works alright for
the edit option, since it's okay (even advantageous) for a user to
bookmark it. However, it's problematic for the delete option. If a user
bookmarks it, and then tries to visit the site later, they might
unintentionally delete something.


If you don't re-use ID values, then as long as delete.php doesn't format
your hard-drive when asked to delete a non-existent ID value, you're OK,
surely?
--
Oli
Dec 22 '05 #5
Thanks for all your input, guys. To answer Oli and Peter's questions,
you're right. Normally there wouldn't be a problem. I am reusing ID
values, though, so there is the possibility that something could get
accidentally deleted. The input has given me an idea for an approach.
Thanks.

Dec 23 '05 #6

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

Similar topics

8
by: Jack Carter | last post by:
I have been delegated to produce a tool that has python embedded in it. The desire is to have a command line interface that inherits all the python scripting functionality so people can use the...
2
by: The Plankmeister | last post by:
Hi, I am converting some queries from stored procedures in MS Access to MySQL, and have hit my first problem. The Access query references another stored procedure, which is where the problem...
0
by: The Plankmeister | last post by:
Ello... I have a textarea for user input for which I've (obviously) specified the cols and rows attributes. The object fills its containing <p> snugly until the user changes the text size in the...
2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
2
by: saiena | last post by:
Is there a way in my regular expression syntax to cause alternating occurences of the search string to be replaced? Here's my code: $item = eregi_replace($search_string, $replace_string,...
2
by: forums_mp | last post by:
I've come full circle on a design here. Consider the case where I've got two modes of operation, uni-cast or multi-cast. In either mode you can transmit(send) and/or receive. The distinction...
0
by: Ima Loozer | last post by:
I have an application I am coding that includes a report that I want to print to a snapshot and display as a subreport on a form. I want the report to be generated for a 5x7 piece of paper to fit...
8
by: winterion | last post by:
Hey, I'm working on a curious webpage: http://www.alphachronicles.com It uses IFRAME to seperate content and navigation, opening new pages and such. If someone wanted to link to content, could...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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...
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...

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.