dimanche 4 octobre 2015

Initial Session Data One Page Behind?

Very new to this stuff so please bear with me. I have read through numerous posts here to try resolving but not getting it to go.

First, yes I am using sessions because I am using this wordpress installation as a Landing Page system with Funnels, and need data to carry through a few pages, populate some conversion forms, and ultimately send updated data back to the CRM (salesforce in this case). Short of the issue below, everything else is working great - so please note this as I'm sure there will be comments about how Wordpress uses cookies instead of sessions etc.

IMPORTANT: In this installation the page template has a start_session() on the first line, and I have also validated that the 'nocache' headers are operating properly, so no caching should be taking place, at least that I am aware of.

The problem I am having is at the starting point of a funnel - I am trying to get my initial Landing Page to clear session data, and repopulate the session with the currently submitted parameter(s). But no matter what I do, the session variables always hold the content from the PREVIOUS page load parameters... so for example, if I initially send:

http://ift.tt/1JNl0NE

The page initially shows nothing when trying to display session['firstName'], i.e. 'Hello, '. NOTE: I can echo the parameter itself, Bob, without issue - so I know the parameter is being read - but it is the resulting session variable from the page load that is the issue.

BUT then, if I hit RELOAD, it works great (In this case, 'Hello, Bob' shows vs. 'Hello, '), conditional code works (a targeted form appears vs. a general form) and everything is good to go.

If I then change address bar to:

.../landingpage/?firstName=Frank

and submit, it still shows 'Hello, Bob'...

Then if I change address bar to:

.../landingpage/?firstName=Jim

and submit, it now shows 'Hello, Frank'. It is as if it is always one page behind when using the SESSION variable to display the data - which means, in general, if I am trying to collect a number of parameters on this first page to use throughout the funnel, it isn't working until another page load occurs - which of course is a problem.

In the landing page, I have tried variations of the code below. Again, as this is a campaign 'entry' page, I need it to establish a new session based on current incoming parameters.

Note: The do_shortcode referenced in the code below is running the plugin that reads the parameters - and by echoing that directly, I can confirm that this is working perfectly, and is registering/displaying the current parameter being submitted to the page.

Also, in testing I am using the variables / shortcode references directly vs. assigning to variables - I know this is incorrect and they should be assigned to variables but I am doing this to make the testing as simple as possible (and I think eliminate complexity as I try to figure this out).

Once I have this figured out, I will likely forgo the shortcode altogether, I am just trying to get this issue fixed first.

Here is an example of what I am trying, (hooked into the page):

  <?php
  $_SESSION = array(); // My understanding that this is supposed to 'unset' all set session variables ??
  echo do_shortcode( '[urlparam param="firstName" default="" /]'); // just a test that runs a shortcode that DOES successfully display the current firstName parameter being submitted
  $_SESSION = array('firstName'=>do_shortcode( '[urlparam param="firstName" default="" /]' )); // 
  ?>

I am then performing an 'echo $_SESSION['firstName'];' on the output page to show - which is where it fails as described above.

I also tried destroying and restarting the session, but once destroyed it never restarts, producing an error that states 'Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent...'

  <?php
  session_destroy();
  session_start(); 
  echo do_shortcode( '[urlparam param="firstName" default="" /]'); 
  $_SESSION = array('firstName'=>do_shortcode( '[urlparam param="firstName" default="" /]' ));
  ?>

I just can't figure out why I'm able to pull and display the current get parameter successfully, but I just can't get it to apply to the session variable on the same page load ...????

Thanks for any thoughts



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire