Page 1 of 1

Last page visited ...

Posted: Sat Jan 15, 2005 1:43 pm
by philippe70

Code: Select all

if (isset($_SESSIONї'last_page'])) {
$last_page = $_SESSIONї'last_page'];
}

$current_page = $_SERVERї'PHP_SELF'];
if (isset($_SERVERї'QUERY_STRING'])) {
$current_page .= "?" . htmlentities($_SERVERї'QUERY_STRING']);
}
$_SESSIONї'last_page'] = $current_page;
When i print $last_page i get the Url of the current page!?!? You know what I've done wrong?

I want to get the url of the last page.

Posted: Sat Jan 15, 2005 1:48 pm
by feyd
$last_page would equal $current_page after a page refresh..

Posted: Sat Jan 15, 2005 1:54 pm
by philippe70
tks for the quit reply.... but you have asuggestion... cause i'm really stock whit this problem... and i don't want to use Query String.

Posted: Sat Jan 15, 2005 1:59 pm
by feyd
avoid setting last_page on the page you don't have to overwrite the "history" information. Only overwrite it once you need to.

Maybe we aren't understanding fully. Could you explain what you are trying to do in detail, please?

Posted: Sat Jan 15, 2005 2:07 pm
by philippe70
1. I have a form

2. I want the action of the form sent the user to the page he was before the form.

3. So in one php page i include on every pages, I put this code, so i always have the last_page the visitor was on.

Code: Select all

if (isset($_SESSIONї'last_page'])) {
$last_page = $_SESSIONї'last_page'];
}

$current_page = $_SERVERї'PHP_SELF'];
if (isset($_SERVERї'QUERY_STRING'])) {
$current_page .= "?" . htmlentities($_SERVERї'QUERY_STRING']);
}
$_SESSIONї'last_page'] = $current_page;
4.

So my form look like this:

Code: Select all

<form name="festimail" method="post" action="<?= $last_page ?>">

Posted: Sat Jan 15, 2005 2:19 pm
by feyd
why not store the url/file/whatever to redirect to stored in the form? It can be dynamic if the form is on multiple pages... potentially, you could store a list of all your pages in a database, or ghetto style it with just listing the specific url to redirect to like this:

Code: Select all

<form method="post" action="processing_page.php">
<input hidden="fromUrl" value="&#123;$_SERVER&#1111;'SCRIPT_NAME']&#125;">
...
you then just load the url in and redirect after processing..

Code: Select all

...
if(isset($_POST&#1111;'fromUrl']))
&#123;
  $urldata = parse_url($_POST&#1111;'fromUrl']);
  if(!is_array($urldata))
    $url = 'http://www.yoursite.com/your_default/page.php';
  elseif(preg_match('#.*\.yoursite\.com#i', $urldata&#1111;'host']))
    $url = 'http://' . $urldata&#1111;'host'] . $urldata&#1111;'path'] . '?' . $urldata&#1111;'query'];
  header('Location: ' . $url);
&#125;

Posted: Sat Jan 15, 2005 2:38 pm
by philippe70

Code: Select all

<?php 
session_start();

if (isset($_SESSION&#1111;'last_page'])) &#123;
$last_page = $_SESSION&#1111;'last_page'];
&#125;

$current_page = $_SERVER&#1111;'PHP_SELF'];
if (isset($_SERVER&#1111;'QUERY_STRING'])) &#123;
$current_page .= "?" . htmlentities($_SERVER&#1111;'QUERY_STRING']);
&#125;
if ($_SERVER&#1111;'PHP_SELF'] != '/festimail.php') &#123;
$_SESSION&#1111;'last_page'] = $current_page;
&#125;
'Voici' my solution! And i will use your tricks to redirect. tks!