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

  • Home
  • SEARCH
  • 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 8532013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:58+00:00 2026-06-11T09:36:58+00:00

I want to set a session variable to 0 when any of a certain

  • 0

I want to set a session variable to 0 when any of a certain set of links are clicked. To do this I have put the following in my javascript file:

$(window).load(function () {
    $("#hdr li a").click(function () {
        $.ajax({
            type: "POST",
            url: "clear.php",
            data: "width=0"
        });
    });
});

(Ignore data: “width=0″… I don’t use this data in clear.php. I put it there because I thought maybe I had to specify a data field.)

and in the file ‘clear.php’ I simply have:

<?php session_start();

$_SESSION['name'] = 0;

?>

So, the idea is that when any of the links in #hdr li are clicked, the user should be taken to the page that the link points to, via clear.php, which sets the session variable to 0.

This works in some browsers (Firefox and Chrome) but not in others (e.g., Safari).

Is this the standard/correct way to implement what I want? Also, how does the browser know where to go after visiting clear.php? Somehow it works, but my first thought was that I should pass the final destination URL into clear.php, and then use “header” to move from clear.php to the final destination.

  • 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-11T09:36:59+00:00Added an answer on June 11, 2026 at 9:36 am

    Is Ajax required? If your re-directing the user to another page & you simply want to pass some data to that page then it may be simpler to include that data in your URL.

    <a href="http://yoursite.com/interesting_page.php?new_session_variable=whatever">Link</a>
    

    Now your php would be simple:

    $_SESSION['name'] = $_GET['new_session_variable'];
    

    Now you’ve removed your dependency on JavaScript, does that make sense? 🙂


    I feel it might be worth mentioning that your approach would be appropriate in certain situations, for example: if you wanted the user to be able to mark one of the links on the page as a favourite. Rather than redirecting them to the same page and reloading the majority of the pages content you might:

    <a class="favourite" data-linkid="link123" href="mylink.php">My Link</a>
    

    // Ensure your page has finished loading aka: 'ready' (almost always)
    $(document).ready(function() {
    
        // Listen for the click event
        $('.favourite').on('click', favoriteLink);
    
        // On the click - post the update via ajax and update your interface
        function favoriteLink(event) {
            event.preventDefault();
    
            // Lets get the link id from our data attribute
            var favourite_link = $(this).data('linkid');
    
            // Post that information via ajax
            $.post('ajax_handler.html', { link : favourite_link }, function(data) {
    
                // And finally do something with the result!
                $('.result').html(data);
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem... I want to set a session variable when clicking
In SessionListener I want to set some values of @ManagedBean with Session scope that
I want set Listbox background to transparent but not working Is there any idea?
My question is : I have an EditText and I want set a margin
i have a problem, i want set text of a UILabel or UItextView or
i have a multiple marker Google map, it works fine but i want set
I have several pages in my application. I have used a session variable called
If I want to set a variable that my whole controller can access, how
I have got below code to GET dictionary type of session variable value. Please
Hello I have a Session ID variable I'm passing through from on Oracle package

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.