Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 22nd, 2005, 02:25 AM
swpulitzer@yahoo.com
Guest
 
Posts: n/a
Default 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.

  #2  
Old December 22nd, 2005, 10:05 AM
Mara Guida
Guest
 
Posts: n/a
Default Re: quandry using GET

swpulitzer@yahoo.com wrote:[color=blue]
> [...] 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.[/color]

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

  #3  
Old December 22nd, 2005, 10:25 AM
Robin
Guest
 
Posts: n/a
Default Re: quandry using GET

swpulitzer@yahoo.com wrote:[color=blue]
> 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.
>[/color]

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
  #4  
Old December 22nd, 2005, 10:45 AM
Peter Fox
Guest
 
Posts: n/a
Default Re: quandry using GET

Following on from swpulitzer@yahoo.com's message. . .[color=blue]
>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.
>[/color]
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
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
  #5  
Old December 22nd, 2005, 12:35 PM
Oli Filth
Guest
 
Posts: n/a
Default Re: quandry using GET

swpulitzer@yahoo.com wrote:[color=blue]
> 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.[/color]

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
  #6  
Old December 23rd, 2005, 01:55 AM
swpulitzer@yahoo.com
Guest
 
Posts: n/a
Default Re: quandry using GET

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.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles