[PHP] Redirection in PHP ? (newbie)

2001-05-14 Thread Nicolas Mermet

Hi, this might be a trivial question but I could not find any docs on that
on php.net.

I am develloping the admin side of a dynamic web site (php/mysql). 
The mechanic is nothing special: a form is submitted and sends the data to
the php page/script that actually does the work of feeding the db. I
noticed that hitting back on the browser make the feeding scripts run
again, and double the entries in the db. Of course, that is what the
scripts are supposed to do :-).

To avoid spamming my db I would like to implement a simple redirection
function, that would redirect the user to the main admin page once the
feeding script has successfully executed and would reduce chances of
double entries. Is there a simple way to achieve that ?

thanks,
Nicolas.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Redirection in PHP ? (newbie)

2001-05-14 Thread Chris Adams

On 14 May 2001 16:54:49 -0700, Nicolas Mermet [EMAIL PROTECTED]
wrote:
 To avoid spamming my db I would like to implement a simple redirection
 function, that would redirect the user to the main admin page once the
 feeding script has successfully executed and would reduce chances of
 double entries. Is there a simple way to achieve that ?

header(Location: index.php) should do the trick.

However, I'd recommend something more robust if avoiding duplicates is a big
deal. For example, if you're using sessions, you might have your addition
script set a confirmation variable using uniqid() and changing it after
updating the DB; if confirmation variable passed in the form submission doesn't
match the session variable, you can redirect them to the Were you really
sure? page. Alternately, depending on your data structure it might be easier
to simply insert a dummy record first and then use UPDATEs from that point
forward.

(The unique confirmation variable approach is also a good idea for security
purposes - otherwise if someone can guess the structure of your application,
they could do something funny like send an HTML email with a link to
/products/delete.php?ID=someIDConfirmed=yes to an admin, which would go
directly through without confirmation if they were logged in at the time.)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]