[SOLVED] stopping a refresh?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

[SOLVED] stopping a refresh?

Post by irealms »

is there a way to stop a page being refreshed or stopping someone from hitting "back" and then going forward again?

Problem is i have an order page but don't want people to be able to place the order again, can't check for orders already in as the id is an auto incremement so is only created on entry into the db.

i did think about a check at the top of the order entry file to see what orders have been placed today by the user but the problem then is they may want to place another order or to place a duplicate.
Last edited by irealms on Thu Oct 28, 2004 2:50 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

One common tactic is to use the php:

Code: Select all

header("Location: script.php");
to move rather than direct links whatever. This overwrites the browser history location rather than creating a new entry.

(Also commonly used for $_POST processing to avoid repetitive entries into a database=.

Example place_order.php script.

Code: Select all

<?php
  if($order_valid) {
   // Write Order:
   header("Location=order_placed.php?ordid=$ordid");
   exit;
  }
  // other calculations
?>
When the user selects back multiple times and then forward the order_placed.php is shown rather than place_order.php.

If the user presses links on the previous screens however they are activating part of the workflow. The normal method is to therefore empty the cart as part of the order_placed script.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

otherwise you could maybe use sessions, like setting a variable when you do the order, and then unset it when it have been processed, no idea, haven't done this before ;)
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

i use sessions for this, like vigge89 suggested

Code: Select all

<?php

if (they submitted an order and you accepted it)
    $_SESSION['order_complete'] = true;
}



// then, just check for the existance of the session variable

if (!isSet($_SESSION['order_complete'])) {
    // process the order
} else {
    echo 'order already submitted';
}

?>
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

rehfeld wrote:i use sessions for this, like vigge89 suggested

Code: Select all

&lt;?php

if (they submitted an order and you accepted it)
    $_SESSION&#1111;'order_complete'] = true;
}
// then, just check for the existance of the session variable
if (!isSet($_SESSION&#1111;'order_complete'])) {
    // process the order
} else {
    echo 'order already submitted';
}
?&gt;
The trouble with this approach is what to do if the person requires a new order. When do you switch this flag variable off ? If you use this approach you will need to reset the flag when a customer adds something to the cart after the order. Then if you go back and forward you still run into the old order creation... Solution: Create a new session for the person on order completion.
Last edited by CoderGoblin on Thu Oct 28, 2004 2:51 am, edited 1 time in total.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

yeah i thought about using sessions for it, i'll have to set them for username and price i think, as we want users to be able to place other orders in same day, but the chances of them placing them for the same price are slim so i'll use that. :)
Post Reply