imsewhi Posted April 19, 2012 Share Posted April 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2012 Share Posted April 19, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338815 Share on other sites More sharing options...
imsewhi Posted April 19, 2012 Author Share Posted April 19, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338817 Share on other sites More sharing options...
imsewhi Posted April 19, 2012 Author Share Posted April 19, 2012 by the way, I should have used way more X's in my example, as that turns out to be a real domain. Not mine of course. Don't click it. My bad. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338818 Share on other sites More sharing options...
batwimp Posted April 19, 2012 Share Posted April 19, 2012 Now you tell me! Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338819 Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2012 Share Posted April 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338824 Share on other sites More sharing options...
imsewhi Posted April 19, 2012 Author Share Posted April 19, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338832 Share on other sites More sharing options...
imsewhi Posted April 19, 2012 Author Share Posted April 19, 2012 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']; Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338834 Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2012 Share Posted April 19, 2012 \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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338846 Share on other sites More sharing options...
imsewhi Posted April 19, 2012 Author Share Posted April 19, 2012 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338853 Share on other sites More sharing options...
DavidAM Posted April 19, 2012 Share Posted April 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1338913 Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2012 Share Posted April 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1339077 Share on other sites More sharing options...
xyph Posted April 20, 2012 Share Posted April 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1339081 Share on other sites More sharing options...
imsewhi Posted April 20, 2012 Author Share Posted April 20, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1339136 Share on other sites More sharing options...
imsewhi Posted April 20, 2012 Author Share Posted April 20, 2012 And in the last code post: <span class="req_btns"> Variable 6</span> could have been written <span class="req_btns"> DESCRIPTIVE LABEL </span>. I'm not trying to display a variable in that area. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1339140 Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2012 Share Posted April 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1339152 Share on other sites More sharing options...
imsewhi Posted April 20, 2012 Author Share Posted April 20, 2012 Thanks again so much everyone. I think I'm understanding this a little better now with your help, and I'll spend some time re-writing a few things. Best wishes. Quote Link to comment https://forums.phpfreaks.com/topic/261259-trying-to-avoid-session-variables-being-destroyed/#findComment-1339187 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.