0

Hi,

I currently have a 1 page site where i am trying to store a session variable and then call it into various other pages that are included when different links are chosen. I currently have the code passing the variable to the first included page but it does not pass to the 2nd included code.

Someone has suggested it is because the variable is initially posted from a form

<?php session_start(); 

$_SESSION['app_name'] = $_POST['app'];
$_SESSION['serv_name'] = $_POST['server'];

?>

And then brought into the page in question

<?php session_start(); 

$app_name = $_SESSION['app_name'] 
?>

I basically then just call $app_name to get the variable.

However..when i try and bring in another page, it doesnt recognise the session variable anymore, as if it has been reset but me clicking on another link. Someone has suggested that this is because the form is posting to itself and that the page must be refreshing without a value when the 2nd link is clicked

they have suggested something along the lines of the following but i really dont know where to start with this. Any help would be much appreciated.

if  
($_POST['app'] is not null) and  ($_POST['app'] == "") then
    $_SESSION['app_name'] = $_POST['app'] ;
endif
3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

with the if statement your session will only be set if the app is blank. i would try it with an isset

<?php
session_start();
if(isset($_POST['app'])){
   $_SESSION['app_name'] = $_POST['app'];
}
?>
0

This now does not pass the variable to any of the pages even though the form was posted.

0
<?php session_start();
if(isset($_POST['app']) && !empty($_POST['app'])){
   $_SESSION['app_name'] = $_POST['app'];
}
echo $_POST['app'];
?>

Clear your cookies and then try.

Edited by rajarajan07: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.