Jump to content

Recommended Posts

Hi,

Does anyone know why session variables might disappear after a form submits data to a third party site (salesforce), which then redirects to the ThankYou page on the original site? Both the form page and the thankyou page have session_start(); at the top.

 

It works fine if I process the form locally, but now I'm supposed to have Salesforce's site process the form, but my thankyou page still needs to read the cookies from the form page in order to display some dynamic links in the text. But now when the thankyou page appears, the session variables seem to have been destroyed.

The redirect back to your site is probably changing the host-name/sub-domain (a www vs no www.) or the path after the domain AND your session id cookie is not setup to match all variations of host-name/sub-domain or paths for your site.

 

What's the complete starting URL on your site (xxxxx out the domain name part if you don't want to post it, but keep everything else as is) and what is the complete URL the redirect goes back to?

 

 

 

Thanks, ok so my page url looks like:

http://www.xxxxxx.com/g/index.php   

The form in index.php has a form action like this:

 

<form action="https://www.Third_Party_site_xxxxxx.com/yadda_yadda_yadda?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="crazyLookingNumbersHere">

<input type=hidden name="retURL" value="http://www.xxxxxx.com/g/thankyou.php">

 

Does that help?

Well the host-name and paths are the same before/after, so that is not the problem.

 

I'll assume that you modified the index.php file and re-uploaded it to the server, in going from the working version (processing the form on your site) to the non-working version.

 

Add the following two lines of code, immediately after your first opening <?php tag and before the session_start() statement in your index.php file, and post any errors you get when you visit the index.php page (xxxyyy out any portion of the errors you don't want to post) -

 

ini_set("display_errors", "1");
error_reporting(-1);

 

Do the same if you modified the thankyou.php page.

I get the following errors:

Notice: Undefined index: variable_1 in E:\INETPUB\WWWROOT\SiteDir\g\index.php on line 8

 

Notice: Undefined index: variable_2 in E:\INETPUB\WWWROOT\SiteDir\g\index.php on line 9

 

Notice: Undefined index: variable_3 in E:\INETPUB\WWWROOT\SiteDir\g\index.php on line 10

 

Notice: Undefined index: variable_4 in E:\INETPUB\WWWROOT\SiteDir\g\index.php on line 11

 

Notice: Undefined index: variable_5 in E:\INETPUB\WWWROOT\SiteDir\g\index.php on line 12

 

 

 

I got no errors for the thankyou page.

Notice: Undefined index: variable_6 in E:\INETPUB\WWWROOT\Dploy\g\sf-test.php on line 13

 

 

And those lines in the code that the errors refer to look like this:  I've changed the variable names here just to make stuff generic:

 

$_SESSION['variable_1'] = $_POST['variable_1'];

$_SESSION['variable_2'] = $_POST['variable_2'];

$_SESSION['variable_3'] = $_POST['variable_3'];

$_SESSION['variable_4'] = $_POST['variable_4'];

$_SESSION['variable_5'] = $_POST['variable_5'];

$_SESSION['variable_6'] = $_POST['variable_6'];

\SiteDir\g\index.php

 

\Dploy\g\sf-test.php

 

^^^ Is that information in the error messages accurate? Are there two different paths (sitedir and dploy) , implying two different domain's and are there two different file names?

 

I've changed the variable names here just to make stuff generic

 

^^^ Programming and troubleshooting programming is an EXACT science. When you do more than xxxyyy out sensitive information in your posts, you change the meaning of the information. You cannot paraphrase, interpret, or alter the meaning of the information you supply about what you did, what your code is, and what result or error you got (unless you want it to take forever to find what is actually causing the problem.)

 

If you didn't get any errors in the thankyou.php page, that means the $_SESSION variables you are referencing on that page DO exist (or you are doing something on that page that is hiding errors and hiding the expected results.) What exact symptom are you getting on the thankyou.php page that leads you to believe the session variables don't exist or don't have any value?

 

What does adding the following to the thankyou.php page, after the session_start() statement, show -

 

echo "<pre>";
echo "SESSION:";
print_r($_SESSION);
echo "</pre>";

 

If the above doesn't pin down what is occurring in your code, you will need to post ALL the code that makes up your index.php and thankyou.php pages (less things like database credentials, payment gateway credentials, actual domain names, but if you have more than one domain involved, indicate where they are being used - xxxxxxx for one, yyyyyy for another) that would be needed to reproduce the problem.

Yeah, that was a mistake with that last path name not being changed.

 

So for the thankyou page, it will display a few links for the user to click on to go to other pages IF they had checked some checkboxes from the previous form. This has been working before I started having a third party process the form. So now that the form's 'action' has been modified to use a third party, the checkbox variables are no longer being passed.

 

Here is the output from the thankyou page after I placed the code you suggested:

 

SESSION:Array

(

    [variable_1] =>

    [variable_2] =>

    [variable_3] =>

    [variable_4] =>

    [variable_5] =>

    [variable_6] =>

)

 

 

 

 

 

If the form were not processing through a third party, I would instead receive this:

SESSION:Array

(

    [variable_1] => SELECTED

    [variable_2] => SELECTED

    [variable_3] => SELECTED

    [variable_4] => SELECTED

    [variable_5] => SELECTED

    [variable_6] => SELECTED

)

Since you have not posted any code, we have to shoot in the dark

 

IF they had checked some checkboxes from the previous form

 

Are you saying the index.php page has a form - that form is posted to a third-party - and you want the values from that form (the form on your index.php page)? Or is there another form before that one.

 

The POST (from index.php) went to the third-party script NOT to your ThankYou page. And, most likely, they are sending you a GET, and sending it WITHOUT your POSTed values. If you want those values, you will have to find a different way to get them.

 

1) Post to your own processing script and use curl to POST to the third-party

2) Create an intermediate script to collect your data and present another form to post to the third-party.

That there are the correct number/name of $_SESSION variables on your thankyou.php page, indicates that they have been set at some point and do actually exist, with the wrong or no values, on your thankyou.php page. You need to find out at what point in your code they are set to the correct values and at what point they are not. The problem will lie somewhere between those two points.

I think DavidAM has this.

 

The third party won't pass those post variables to your thankyou page for you.

 

In this case though, cURL probably won't work, as the third party site probably has some form of authentication for the user to fill out.

 

I'd say the easiest solution is probably JavaScript. Have the form post to your own site to set the session variables, via AJAX, and once that completes, post the form to the 3rd party.

Thank you very much to everyone for your help. I thought I could make it easy by just describing, without posting code, but that was my mistake. Here is some basic, stripped down code that might hi-lite my error:

 

form page:

<?php
ini_set("display_errors", "1");
error_reporting(-1);

session_start();

$_SESSION['variable_1'] = $_POST['variable_1'];
$_SESSION['variable_2'] = $_POST['variable_2'];
$_SESSION['variable_3'] = $_POST['variable_3'];
$_SESSION['variable_4'] = $_POST['variable_4'];
$_SESSION['variable_5'] = $_POST['variable_5'];
$_SESSION['variable_6'] = $_POST['variable_6'];

?>
<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <META> element to your page <HEAD>.      -->
<!--  If necessary, please modify the charset parameter to specify the        -->
<!--  character set of your HTML page.                                        -->
<!--  ----------------------------------------------------------------------  -->
<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <FORM> element to your page.             -->
<!--  ----------------------------------------------------------------------  -->
<body>
<form action="https://www.A-SALESFORCE-SITE-TO-ADD-THE-USER-TO-SALES-DATABASE.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
  <input type=hidden name="oid" value="ALPHA-NUM-VALUE-HERE">
  <input type=hidden name="retURL" value="http://www.mysite-WWXXYYZZ.com/g/thankyou-test.php">
  <!--  ----------------------------------------------------------------------  -->
  <!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
  <!--  these lines if you wish to test in debug mode.                          -->
  <!-- <input type="hidden" name="debug" value=1>                              -->
  <!--   <input type="hidden" name="debugEmail" value="email@mysite-WWXXYYZZ.com">       -->
  <!--  ----------------------------------------------------------------------  -->
  <p>
    <label  for="variable_1" class="checkbox">
    <input class="checkbox" type="checkbox" name="variable_1" value="SELECTED" id="variable_1" 
            <?php 
		  if ($_POST['variable_1'] == 'SELECTED') echo 'checked="checked"';
		?>
            />
    Variable 1</label>
  </p>
  <p>
    <label  for="variable_2" class="checkbox">
    <input class="checkbox" type="checkbox" name="variable_2" value="SELECTED" id="variable_2" 
            <?php 
		  if ($_POST['variable_2'] == 'SELECTED') echo 'checked="checked"';
		?>
            />
    Vairable 2</label>
  </p>
  <p>
    <label for="variable_3" class="checkbox">
    <input class="checkbox" type="checkbox" name="variable_3" value="SELECTED" id="variable_3" 
            <?php 
		  if ($_POST['variable_3'] == 'SELECTED') echo 'checked="checked"';
		?>
            />
    Variable 3</label>
  </p>
  <p>
    <label for="variable_4" class="checkbox">
    <input class="checkbox" type="checkbox" name="variable_4" value="SELECTED" id="variable_4" 
            <?php 
		  if ($_POST['variable_4'] == 'SELECTED') echo 'checked="checked"';
		?>
            />
    Variable 4</label>
  </p>
  <p>
    <label for="variable_5" class="checkbox">
    <input class="checkbox" type="checkbox" name="variable_5" value="SELECTED" id="variable_5" 
            <?php 
		  if ($_POST['variable_5'] == 'SELECTED') echo 'checked="checked"';
		?>
            />
    Variable 5</label>
  </p>
  <p>
    <label for="variable_6" class="checkbox">
    <input class="checkbox" type="checkbox" name="variable_6" value="SELECTED" id="variable_6" 
            <?php 
		  if ($_POST['variable_6'] == 'SELECTED') echo 'checked="checked"';
		?>
            />
    Variable 6</label>
  </p>
  <p> </p>
  <input type="submit" name="submit">
</form>
</body>
</html>

 

 

thankyou page:

<?php 
session_start();

echo "<pre>";
echo "SESSION:";
print_r($_SESSION);
echo "</pre>";

?>
<body>
  <?php 
  if (($_SESSION['variable_1'] == 'SELECTED') ||
  	      ($_SESSION['variable_2'] == 'SELECTED') ||
      ($_SESSION['variable_3'] == 'SELECTED') ||
	  ($_SESSION['variable_4'] == 'SELECTED') ||
	  ($_SESSION['variable_5'] == 'SELECTED') ||
	  ($_SESSION['variable_6'] == 'SELECTED')) {
              echo 'Here are the materials you requested:';
  }
  ?>

      <?php 
  if ($_SESSION['variable_1'] == 'SELECTED') {
     echo '<a href="link-to-file1.pdf" target="_blank"><span class="req_btns"> Variable 1</span></a>';
  }
  if ($_SESSION['variable_2'] == 'SELECTED') {
     echo '<a href="link-to-file2.pdf" target="_blank"><span class="req_btns"> Variable 2</span></a>';
  } 
  if ($_SESSION['variable_3'] == 'SELECTED') {
     echo '<a href="link-to-file3.pdf" target="_blank"><span class="req_btns"> Variable 3</span></a>';
  } 
  if ($_SESSION['variable_4'] == 'SELECTED') {
     echo '<a href="link-to-file4.php" target="_blank"><span class="req_btns"> Variable 4</span></a>';
  } 
  if ($_SESSION['variable_5'] == 'SELECTED') {
     echo '<a href="link-to-file5.php" target="_blank"><span class="req_btns"> Variable 5</span></a>';
  } 
  if ($_SESSION['variable_6'] == 'SELECTED') {
     echo '<a href="link-to-file6.php" target="_blank"><span class="req_btns"> Variable 6</span></a>';
  } 
  ?>
</body>
</html>

 

Thank you again very much. And I will study the replies I've already received so that I can get a better understanding of all of this.

Kind Regards

Is this correct - your index.php page correctly shows the right check boxes as being checked, right before you press the submit button and goto the payment gateway page?

 

The code you did post for index.php is not testing if there was a form submission to it by your previous page, so any time it gets requested, it will unconditionally assign values to the $_SESSION variables. When it gets requested without any $_POST data, the $_SESSION variables will be assigned null/empty values (or perhaps your code later on in the index.php page is clearing those session variables.)

 

I doubt your payment gateway is making a GET request to your index.php page, but it could. It's more likely your browser is requesting the index.php again or you have some code on that page that is clearing the session variables instead of testing them (one = sign instead of two == signs) or your thankyou.php page is redirecting back to the index.php page at some point, or you have some rewrite rules that are causing the index.php to be requested again.

 

Your code that assigns the values to the $_SESSION variables needs to be inside of a conditional test so that it will only be executed as the result of a form submission. This will fix the most immediate problem, but you need to determine why and how the index.php page is being requested again, to prevent unnecessary requests and to fix the actual problem in case it is causing other unexplained operations.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.