Page 1 of 1

question about going back to a page

Posted: Sat Aug 07, 2004 12:49 am
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.

Posted: Sat Aug 07, 2004 12:53 am
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?

Posted: Sat Aug 07, 2004 1:01 am
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 :)

Posted: Sat Aug 07, 2004 1:38 am
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

Posted: Sat Aug 07, 2004 2:06 am
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.

Posted: Sat Aug 07, 2004 2:17 am
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..

Posted: Sun Aug 08, 2004 4:00 am
by C_Calav
thanx LiLpunkSkateR!

will try it out now

Posted: Sun Aug 08, 2004 4:08 am
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?

Posted: Sun Aug 08, 2004 4:08 am
by timvw
At http://www.tonymarston.net/php-mysql/ba ... blues.html you can find some inspiration at 2-) Maintain a program stack.

Posted: Sun Aug 08, 2004 4:12 am
by C_Calav
thanx timv

Posted: Sun Aug 08, 2004 4:12 am
by C_Calav
on my test scripts its when you click go back its the same link as the page im on?

Posted: Sun Aug 08, 2004 5:28 am
by malcolmboston

Code: Select all

$_SERVER['HTTP_REFERER'];
????

Posted: Sun Aug 08, 2004 5:47 am
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();

Posted: Sun Aug 08, 2004 7:46 am
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!