Rocco The Taco
Rocco The Taco

Reputation: 3777

PHP if empty condition is ignored

I have the following code on a web page that is entered by a number of unique URLs.

This web page cannot use history.back or other javascript as it is impossible to account for the amount of clicks on this page.

I came up with this solution below to try to get & save the original referer page URL for later use. Basically upon page entry if the SESSION Variable whodat1 is empty it should populate. The only problem is that session is overwritten each time a page refresh occurs.

How do I make this session permanent or not overwritten when the page refreshes?

    <!-- back to map button-->
    <?php 

    if(isset($_SERVER['HTTP_REFERER'])) {

        if(empty($_SESSION["whodat1"])) 
                $_SESSION["whodat1"] = $_SERVER['HTTP_REFERER']; 
                //echo $_SESSION["whodat1"];


        ?>
    <input type="button" value="Back To Maps" id="show" onClick="window.location.href='<?= $_SESSION["whodat1"] ?>'" style="height:30px; background-color:#006; color:white;"> 

 <?php }?>

Upvotes: 0

Views: 61

Answers (1)

Echo
Echo

Reputation: 98

Refreshing won't make session disappear or expire. Make sure you have

session_start()

Upvotes: 2

Related Questions