Archived

This topic is now archived and is closed to further replies.

  • 0

Session variable not passing from one hook to the other

Question

Posted · Report post

I have two hooks on the same page at "pagelines_before_html" and "pagelines_loop_before_post_content" arranged as follows;

hook @ pagelines_before_html:

<?php
session_start();
.
.
$errmsg_arr[] ='some error message';
.
.
$_SESSION['ERRMSG_ARR'] =$errmsg_arr;
?>
  hook @ pagelines_loop_before_post_content:
<html>
.
title code
.
<?php
   if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {

     echo '<ul class="statusmsg">';

     foreach($_SESSION['ERRMSG_ARR'] as $msg) {

       echo '<li>',$msg,'</li>';

     }

     echo '</ul>';

     unset($_SESSION['ERRMSG_ARR']);

   }
?>
.
form code
.
</html>

 

Web page;

http://s16389982.onlinehome-server.com/wordpress2/?page_id=325

 

The problem is nothing gets printed even though the message is setup correctly in the first hook.  Is there something I am missing to get SESSION variables to work across hooks?

 

-Trevor

Share this post


Link to post
Share on other sites

4 answers to this question

Posted · Report post

Hi,  I have this working now.  The session variable cleanup, unset $_SESSION[variable] was causing updates by the hook at pagelines_before_html to not take effect.  You can monitor SESSION updates by reading the session file at session.save_path or /var/lib/php/session/sess_{session id}.  That will lead you to where the culprit is.

Share this post


Link to post
Share on other sites

Posted · Report post

Can you use a pastebin for your code, its pretty much unreadable above,

 

http://paste.pagelines.com

Share this post


Link to post
Share on other sites

Posted · Report post

Yes, I pasted the code to the paste bin.

Share this post


Link to post
Share on other sites

Posted · Report post

Hmm, well....

 

1st, wordpress does not use sessions, not sure why your trying to use them either. Nothing wrong with using global variables seeing as the page is only rendered once the variable can be globalized and shared between 2 hooks on the same page.

 

2nd your using raw sql stuff there, thats very dodgy. You should try and use the built in wordpress database api to sanatize all that stuff.

Share this post


Link to post
Share on other sites