Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:35:10+00:00 2026-06-18T05:35:10+00:00

Is there a way to persist url parameters throughout the site as you click

  • 0

Is there a way to persist url parameters throughout the site as you click around? I’m working on a demo site which sets a url parameter on the first page to determine what’s shown on the following pages. I would use session variables but the internal users are likely to share links between one another and the session wouldn’t exist then. I’ve tried googling but all that returns are articles related to php frameworks like Cake. Is there a way to achieve this without using a framework?

Example of the Flow:

  • Select Page > User selects Use Case and presses Submit to view Demo Site
  • Inner Pages > Detect URL parameter and show data based on Use Case.
  • As user clicks through the demo site the parameter persists so it shows the relevant data.
  • When user returns to Select Page they can choose a new Use Case and repeat above actions.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:35:11+00:00Added an answer on June 18, 2026 at 5:35 am

    You could simply add a url parameter with the selection, and make sure it’s always found in all internal links. I assume you don’t want to do that because it’s too many changes.

    Some alternate ideas:

    IDEA 1:

    Save the initial selection inside the session or inside a cookie. Also add an optional url parameter for all pages, which also holds the selection. To avoid changing all of your internal links, check server-side if the selection url parameter was given. If it wasn’t, redirect immediately to the same url, just with the url parameter added (according to the session/cookie). This way the url parameter will always appear without changing all the internal links everywhere, and users can still share links.

    For implementation sake, let’s assume our session variable is $_SESSION['sel'] and that our optional URL parameter is psel. Let’s assume all pages in the site are served via php. The following lines of php should appear in the top of all pages (can be placed in a separate php file and included in each page):

    if (!isset($_REQUEST['psel']))
    {
      header('Location: '.$_SERVER['REQUEST_URI'].'&psel='.$_SESSION['sel']);
      exit;
    }
    

    This is pseudo code, I’m on my iPad so excuse me if it’s a bit short and not perfect. What this line does is check if the URL param is defined, and if not, redirect (to the same page) and define it according to our session variable. This way even if we have an internal link which doesn’t include the URL param, this redirect will add it. There’s a small bug regarding ? in the request uri, I’ll let you fix it.

    This code does not change all of the internal links, all it does is the following: when an internal link is visited and the URL param is omitted (as it normally would), this code will stop the page from displaying without the param and redirect to the same page with the param.

    Another important piece of code is to change our session variable in case the URL param was defined. This can be done by adding this else block to the code above:

    else $_SESSION['sel'] = $_REQUEST['psel'];
    

    This way, when the URL is shared by 2 users, it will always include the psel URL param and when the new user first visits it, it will set his session variable accordingly.

    IDEA 2:

    Create a “fake” directory for every selection. For example, let’s say you site was http://example.com/index.php then you’ll have http://example.com/sel1/index.php and http://example.com/sel2/index.php. These directories aren’t real, and using .htaccess rewrites (or even symbolic links in the FS) will actually point to the original files. Except, now you have this magic parameter in the path. This is useful because the path will remain the same through all relative links, meaning you don’t have to change all internal links. If you need to access the current selection, you can easily get it by parsing the path of the current url.

    This idea I think is a bit better because it achieves the same thing without redirects. It will be easiest to explain with a symbolic link, but keep in mind this can also be done with .htaccess rewrite rules. A symbolic link in Linux is a path that links to another path. If I run the following console commands (usually using SSH on my server):

    ln -s . sel1
    ln -s . sel2
    

    It will create 2 directories inside . (the local directory), named sel1 and sel2, but they are just links to the original current directory. If this current directory is my web server document root, the effect is that accessing:

    http://example.com/sel1/index.php
    

    Will actually access:

    http://example.com/index.php
    

    Note that this isn’t a copy of the directory. If I make changes to index.php or any other file in the local directory, these changes will also be reflected in /sel1 and /sel2

    How does this help? Instead of accessing my regular site, if I want to show selection 2 I will use the URL http://example.com/sel2/index.php. Because of the symbolic link, this URL will behave exactly like my original website http://example.com/index.php.

    Now let’s assume I want to check in php if I’m showing selection 2 or not, I can simply examine the variable $_SERVER['REQUEST_URI'] and see if it includes the path /sel2 or not.

    This path will remain persistent between all internal URLs because they are usually relative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to persist an string from an online click once application.
is there any way to persist (preserve) parameters in Rails controller? It should be
is there a simple way to persist some of the fields in another class
What is the best way to persist/save printer settings in .Net? There used to
Is there a way we can persist javascript variables across various pages? Suppose in
I am wondering if there is a way to persist variables in the business
What's the best way to persist user state with Tomcat/Scala? My first thought is
Is there a way of telling GORM not to persist a property? I'm planning
Is there a way to find out which record caused such a violation in
Is there a way to persist changes to an HTML page via a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.