question about going back to a page

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
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

question about going back to a page

Post by C_Calav »

hi guys,

what is the right code to use on a link to get the user to get directed back to the page they were just on.

for example, a shopping cart, they add item, goes to the shopping cart, now i want a link to go back to the page they were just on.

what should i look up to do this?

thanx.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

javascript: history.back() or variants..

or.. what I typically do: send a 'from' variable, either through the url or sessions of where they previously were and create a forward link to that location to "continue shopping"

didn't we just talk about this recently?
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

yeah we did, but i dont know how to go about it :?

can you explain the form variable technique a bit more please?

thanx :)
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

can someone please explains feyds second method please, i dont know what to do. or someone point me in the right direction?

thanx
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. on the originating pages.. you set a session variable with the url or some facsimile.. on your additem resultant page, you create a link back to that page using the data stored in the session.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

test.php:

Code: Select all

<?php
session_start();
$filename = "test.php";
$last = $_SESSION['last'];
$_SESSION['last'] = $filename;
echo "<a href="test2.php">Go Foward</a>";
echo "<a href="" .$last. "">Go back</a>";
?>
test2.php:

Code: Select all

<?php
session_start();
$filename = "test2.php";
$last = $_SESSION['last'];
$_SESSION['last'] = $filename;
echo "<a href="test3.php">Go Foward</a>";
echo "<a href="" .$last. "">Go back</a>";
?>
Ask if you still have questions..
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx LiLpunkSkateR!

will try it out now
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

i dont get how this works..

for all my products pages i add this code in?

and define eveypage with $filename = "test.php"; ?

is this right?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

At http://www.tonymarston.net/php-mysql/ba ... blues.html you can find some inspiration at 2-) Maintain a program stack.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx timv
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

on my test scripts its when you click go back its the same link as the page im on?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

$_SERVER['HTTP_REFERER'];
????
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

http_referer does not always work.

Code: Select all

function geturl()
{
  $ports = array('https' => 443, 'http' => 80);
  $prefix = empty($_SERVER['HTTPS']) ? 'http' : 'https';
  $url = $prefix;
  $url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : '';
  $url .= '://';
  $url .= $_SERVER['HTTP_HOST'];
  $url .= $_SERVER['REQUEST_URI'];
  return $url;
}

echo geturl();
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

I think Javascript would be a good choice for this, however not all browser's use JS, therefore PHP may be the best of choices!
Post Reply