need help with passing of variable using $_session please

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 9, 2019   (RSS)

Hi all,

let me say at the outset that I have no php coding skills so all my work tends to be guesswork so please excuse any ignorance or lack of knowledge displayed.

my ultimate goal with this is to be able pass a variable into a form in an inline frame.  At the moment I am just trying to get the variable transfer to work.

I have the following header code in the host page which draws record info from the url, ie business-detail-test.php?New-Advertiser-313

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('/home/sites/4b/4/4af2cde633/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load record from 'advertisers'
  list($advertisersRecords, $advertisersMetaData) = getRecords(array(
    'tableName'   => 'advertisers',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $advertisersRecord = @$advertisersRecords[0]; // get first record
  if (!$advertisersRecord) { dieWith404("Record not found!"); } // show error message if no record found

?>
<?php
	session_start();

$_SESSION['email_address2']=($advertisersRecord['email_address']) ;

?>

I have created a simple test page (test.php) to test the $_session element works correctly which is coded as

<?php
	session_start();
echo $_SESSION['email_address2'];

	
?>

This seems to work as expected with test.php displaying the records email address.

within the original page "business-detail-test.php?New-Advertiser-313" I have to include an enquiry form which has been created using coffee cups web form builder software which by default brings a created form into a page via the use of an inline frame.  The code they provide for doing this is as shown below which I will now refer to as formcode1

<script type="text/javascript">document.write(unescape("%3Ciframe id=\"fb_iframe\" src=\"availability-request.php" + window.location.search + "\" width=\"100%\" height=\"1158\"allowtransparency=\"true\" scrolling=\"no\" frameborder=\"0\"%3E&lt;a href=\"availability-request.php\" title=\"availability-request\"&gt;Check out my CoffeeCup Form&lt;/a&gt;%3C/iframe%3E"));</script>
<noscript>
  <iframe height="1158" style="border:none; background:transparent; overflow:hidden; width:100%;"
  id="fb_iframe" src="/availability-request/availability-request.html">
    <a href="availability-request.php" title="availability-request">Check out my CoffeeCup Form</a>
  </iframe>
</noscript>

For some reason, when formcode1 is added to my "business-detail-test.php?New-Advertiser-313" my test.php page no longer displays the email address assigned in the $_session code from which I assume that the $_session data is no longer being set but havent a clue why adding the above to the page would stop this from happening.

Through process of elimination I have found that the part of formcode1 which is causing the issue seems to be the code below as removing that element allows test.php to work again but I cannot see any reason why loading the iframe should stop $_session from working.

<noscript>
  <iframe height="1158" style="border:none; background:transparent; overflow:hidden; width:100%;"
  id="fb_iframe" src="/availability-request/availability-request.html">
    <a href="availability-request.php" title="availability-request">Check out my CoffeeCup Form</a>
  </iframe>
</noscript>	

the coffee cup form is processed by a file called form.cfg.php and it is this file that I want to ultimately transfer the $_session value into so that the form can be sent to the correct email. I assume that all I need to do is copy the code from test.php into the top of form.cfg.php to be able to use the variable to within that page but I need to ascertain why I am losing the variable content from the $_session element.

Sorry if I have made the whole thing confusing by trying to give as much information as possible but to clarify i just need to know why adding an iframe to a page would break the $_session code.

Thanks in advance for any help provided, I know I can resolve the issue by just coding the form into the page by hand but the coffee cup solution provides a lot of functionality that I would prefer not to lose.

By daniel - January 7, 2019

Hi Willydoit,

That's an interesting issue you have there; the section you identify is inside <noscript> tags, so unless you have javascript disabled on the page, it shouldn't actually be doing anything on your page - let alone modifying the session.

How are you including/viewing test.php? Is it also in an iframe? If that's the case, it might be easier to pass in the value through a URL parameter rather than a session. So the iframe code could look something like this:

<iframe src="test2.php?email_address=<?php echo $advertisersRecord['email_address']; ?>"></iframe>

And then you could access that value in test.php with the following:

echo $_GET['email_address'];

If you'd still like to try to get the session method working, my suggestion would be to try moving the test.php iframe HTML above the coffee cups snippet; this could help rule out a couple different issues.

Hope that helps!

Cheers,

Daniel
Technical Lead
interactivetools.com

Hi Daniel,

Thanks for looking at this. Unfortunately I posted tne wrong code, it is the script element of the code that causes the issue.