jim.davidson Posted April 24, 2008 Share Posted April 24, 2008 I'm having a problem, my code works fine when I run it on my localhost. When I load it to the "live" server some session variables disappear. I did a check a find that my localhost is running version 5.2.0 but the "live" server is running version 4.4.7. Could this be my problem? Do the two version handle session variables differently? Any guidance will be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/102758-i-have-a-question-about-session-variables/ Share on other sites More sharing options...
soycharliente Posted April 24, 2008 Share Posted April 24, 2008 Maybe this will help? It's a possibility. http://us.php.net/manual/en/ref.session.php#55903 Quote Link to comment https://forums.phpfreaks.com/topic/102758-i-have-a-question-about-session-variables/#findComment-526308 Share on other sites More sharing options...
wildteen88 Posted April 24, 2008 Share Posted April 24, 2008 PHP does not handle sessions differently from version to version. Could you post a snippet of your code where your use sessions. It maybe a PHP configuration issue. Quote Link to comment https://forums.phpfreaks.com/topic/102758-i-have-a-question-about-session-variables/#findComment-526317 Share on other sites More sharing options...
jim.davidson Posted April 24, 2008 Author Share Posted April 24, 2008 Page one has a dropdown menu to select a customer by name if (!isset($_SESSION)) { session_start(); } $cust_id = ''; This is the part of the code where $cust_id comes from <td><div align="left"> <select name="cust_id" id="cust_id" class="textbackground"> <option value="" <?php if (isset($error) && isset($_POST['cust_id']) == $cust_id) { echo 'selected="selected"';} elseif ($firstid == $cust_id) {echo "selected=\"selected\"";} ?>> </option> <?php do { ?> <option value="<?php echo $row_getCust['customer_id']?>"<?php if (!(strcmp($row_getCust['customer_id'], $firstid))) {echo "selected=\"selected\"";} ?>> <?php echo $row_getCust['last_name']?> <?php echo $row_getCust['first_name']?> <?php echo $row_getCust['mi']?> </option> <?php } while ($row_getCust = mysql_fetch_assoc($getCust)); $rows = mysql_num_rows($getCust); if($rows > 0) { mysql_data_seek($getCust, 0); $row_getGetCust = mysql_fetch_assoc($getCust); }?> </select> </div></td> After customer is selected from the dropdown menu, I store $cust_id to session variable if (!empty($_POST['cust_id'])) { $_SESSION['cust_id'] = $cust_id; } Now I go to another page to display that customer's info if (!isset($_SESSION)) { session_start(); } echo 'customer id = '; echo $_SESSION['cust_id']; When I'm on the localhost the result is - customer id = 4 When I'm on the "live" server the result is - customer id = Quote Link to comment https://forums.phpfreaks.com/topic/102758-i-have-a-question-about-session-variables/#findComment-526349 Share on other sites More sharing options...
soycharliente Posted April 25, 2008 Share Posted April 25, 2008 The only thing I can say right now after looking at that is that you don't need to do this: if (!isset($_SESSION)) { session_start(); } session_start() creates a session or resumes the current one. Therefore, there's no need for any if statements. You say session_start() at the top of every page that you're using session variables on. At the very top. Before anything else. If there is a session, it resumes it. If not, it starts a new one. The manual Quote Link to comment https://forums.phpfreaks.com/topic/102758-i-have-a-question-about-session-variables/#findComment-527012 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.