1

I have set up a site which has a home page for each area they service. In Chrome and Safari if you goto the service areas tab and select a service area you will be taken to that areas home page.

At this point a session is started to store the users selected area and if they visit another page on the site it now displays a location specific ad in the header for that selected location or if they select home it will redirect them to their selected area home page.

The problem in Firefox is that if you select a service area and are taken to that areas home page then select a different page from the menu the set service area changes to a different area. This only occurs when leaving the custom home page to a different menu page.

This is the code that sets the session:

session_start();

$cur_url = dd_cur_page_url();

if ('local_home_pages' == get_post_type() && $cur_url != $_SESSION['dd_location']['home']) {
    $cur_url_mod = str_replace('carpet-cleaning_', '', $cur_url);
    $url_parts = explode('/', $cur_url_mod);
    $url_parts_count = count($url_parts);
    $cur_page = $url_parts[$url_parts_count - 2];
    $location_parts = explode('_', $cur_page);
    $place = trim(str_replace('-', ' ', $location_parts[0]));
    $state = trim(str_replace('-', ' ', substr($location_parts[1], 2)));
    $state_parts = explode('-', $location_parts[1]);
    $state_abv = trim($state_parts[0]);
    $county = trim(str_replace('-', ' ', $location_parts[2]));
    $_SESSION['dd_location'] = array(
            'home' => $cur_url,
            'place' => $place,
            'state' => $state,
            'state_abv' => $state_abv,
            'county' => $county);
}

And this is the redirect code which only runs on the generic home page:

session_start();

$cur_url = dd_cur_page_url();

if (is_front_page() && isset($_SESSION['dd_location']['home'])) {
    $location = $_SESSION['dd_location']['home'];
    header('Location:' . $location);
}
4
  • Can we see the get_post_type() and is_front_page() functions? Also can you include a var_dump of $_SESSION for both pages? Commented Oct 15, 2013 at 3:06
  • They are built in wordpress functions. is_front_page returns true if it is the site homepage. If this is the case the user is redirected to their selected area home page. get_post_type returns the post type of the page. If it is a post type of local_home_pages and it is a different local home page from the page set in the session the session info is updated if it is the same it leaves the session alone. Commented Oct 15, 2013 at 3:33
  • I will add a var dump in the header till a solution is found. Commented Oct 15, 2013 at 3:37
  • did you try CTRL+f5 ?? Commented Oct 15, 2013 at 4:58

1 Answer 1

1

After some debugging with firebug I found the problem. It was in firefox's prefetch. I added the following to my .htaccess file and everything is now working.

RewriteEngine on
RewriteCond %{HTTP:X-moz} prefetch
RewriteRule . . [F,L] 

I will write a post on this issue coving how I found it, what to do to fix it, and why it occurred on my website http://www.dominant-domains.com within the next few days for those who are like me and want more than just a fix.

Thank you to the community for your suggestions. This was my first time here and it was a pleasurable one! Cheers

Sign up to request clarification or add additional context in comments.

1 Comment

Not even going to pretend I understand why this works, but you just saved me tearing my hair out anymore, thanks! One of my session variables I was saving was being incremented by 1 on every subsequent page load (only on FireFox). I thought I was going mad!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.