Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Back Button action whilst adding Session Variable? 1

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
I am relying on SESSION VARIABLES to select various features presented on my webpages. The SV is to be one of three town names. In the event of a page being called and there is no SV I want to divert to a page where the user can select one of three towns, submit their choice and be directed back to the previous page (with the SV now in place)
Can anyone help with some php code that would achieve this manoeuvre?
 
this is the way to do what you described.
it can be streamlined a lot and it would be better to use a single script for everything and choose what to display the user based on a despatch method.
Although if you require multiple pages of your site to be SEO then the despatch method might not be the best on its own (you can get around the issue of SEO by using mod_rewrite).

Code:
session_start();
$selectPage = '' ; //url of page which is used to select the town
if (empty($_SESSION['SV'])){
  $_SESSION['callingPage'] = $_SERVER['REQUEST_URI'];
  header('Location: '.$selectPage);
  exit;
}

Code:
session_start();
code to allow town to be set.  selection submitted to townSelect.php

Code:
session_start();
if (!empty($_POST['SV'])){
  $_SESSION['SV'] = $_POST['SV'];
  if (!empty($_SESSION['callingPage'])){
    header ('Location:'. $_SESSION['callingPage']);
    exit;
  }
}
 
Many thanks, jpadie.
That's brilliant!
Sorry it's taken so long to reply, I've been away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top