A comples problem to explain...

All Quick 'n Easy Web Builder support issues that are not covered in the forums below.
Post Reply
alex4orly
Posts: 321
Joined: Thu Jul 23, 2020 9:34 am

A comples problem to explain...

Post by alex4orly »

Page Loading sequence, please read carefully

1) Index. Php – checks for session start and other things
2) If OK, redirect to → writelog.php, carifies user, creates cookie
3) if OK –> redirects to homepage.php this is the site home page
It has on it 8 buttons, each one is leading to another topic

As part of homepage.php is a Modal hidden dialogue. Clicking any of the above 8 buttons is loading and opens the said hidden dialog and it loads a new page into an iFrame that is part of that hidden dialog.

4) The button click (one of the 8 buttons) is triggering an Event that calls a javascript function with the required details of what page to load into the iFrame. One of the target pages is called
thewars2.php

The site keeps track through a number of SESSION Variables on various data items required. The session variables exist all the way to step 3 above, but step-4 doesn’t have them. I decided to create a cookie in stage 2 and store into it what I need in step 4. But, that doesn’t do the trick either…

BUT – if I exceute the page thewars2.php directly : https://www.squadron-125.org.il/thewars2.php – the page reads the cookie and has the data in it (visitor’s name). But this of course is NOT a solution.

Any suggestions, why and how to resolve it?

Cheers
Alex
User avatar
Pablo
Site Admin
Posts: 3918
Joined: Mon Feb 13, 2006 7:00 am
Location: Europe
Contact:

Re: A comples problem to explain...

Post by Pablo »

I do not think this is related to the software. Cookies and sessions variables are not processed by the software, but by the browser.
But maybe you forgot to start the session at the start of the page?
alex4orly
Posts: 321
Joined: Thu Jul 23, 2020 9:34 am

Re: A comples problem to explain...

Post by alex4orly »

This is nothing to do with the software.
Yes, I start the session first thing at the top of each page

Cheers
alex4orly
Posts: 321
Joined: Thu Jul 23, 2020 9:34 am

Re: A comples problem to explain...

Post by alex4orly »

OK, I figured out a fix around the problem

On the home screem, a click on any one of the 8 buttons the click event call the following Javascript function:
function showTopic(htmlPage)
{
// At this point, the $_SESSION is already invoked
VisitorName = '<?php echo $_SESSION['fullname']; ?>';

// This is to remove spaces from the Visito's name
VisitorName = VisitorName.replace(/\s/g, '');

// The argument here is passed from the onclick of the button calling it
// I pass the visitpr's name because the call goes to the page writing the log
pageName = htmlPage + "?" + "x=" + VisitorName;

$('#Dialog1').dialog('open'); // The Dialog is initially hidden on page load

var url = 'https://squadron-125.org.il/';
var goto = url.concat(pageName);
window.open(goto , 'InlineFrame1'); // Show the HTML page inside the iFrame
}
The "Strange thing is" - why is the $_SESSION data NOT available in the target page if I run it through the above script, is that because it goes into an iFrame? If I execute the target page directly (not through the above script) the $_SESSION data is avialable

The target page that is loaded through the above Javascript, has in the "Onload" the following Ajax call:
function registerVisit()
{
$.ajax({
url : 'phpwrite.php',
type : "GET"
});
}
This is inserted into all the 8 pages that are called by each one of the 8 buttons on the home screen

The target PHP scrip is in a seprate external file "phpwrite.php" with the following content in it
$actual_link = $_SERVER['HTTP_REFERER']; // Referring page
$visitorName = substr($actual_link, strrpos( $actual_link, '=' )+1);
// The visitor's name is the last part of the url, I just need that.

$toremove = "?x=" . $visitorName; // need to remove this part from th url
$actual_link = str_replace($toremove, "",$actual_link); // the page calling.html

date_default_timezone_set('Australia/Melbourne');
$dt = new DateTime();
$today = $dt->format('Ymd H:i:s');

$logdata = "\r\n";

$story = basename($actual_link); // remove the url, I jast need the page calling name

$output = $today . "," . $story . "," . $visitorName . $logdata;

$file = fopen("visits.csv","a");
fwrite($file,$output);
fclose($file);
OK, all works now just fine, I thought maybe someone else can learn somthing from it.

Cheers
User avatar
Pablo
Site Admin
Posts: 3918
Joined: Mon Feb 13, 2006 7:00 am
Location: Europe
Contact:

Re: A comples problem to explain...

Post by Pablo »

Thanks for sharing your solution!
alex4orly
Posts: 321
Joined: Thu Jul 23, 2020 9:34 am

Re: A comples problem to explain...

Post by alex4orly »

My question however remains
Why can't I get session data when I load the page into the IFrame?

Cheers
User avatar
Pablo
Site Admin
Posts: 3918
Joined: Mon Feb 13, 2006 7:00 am
Location: Europe
Contact:

Re: A comples problem to explain...

Post by Pablo »

I cannot explain why it does not work in this specific case.
But it may be related to the way sessions work in general.
The session ID and cookies are transfered via the header of the http request between the browser and the server.
The inline frame may have a different session id than the main page because of security restriction.
Or there may be a timing problem, where the session data is not available when the browser requests the inline frame page.
alex4orly
Posts: 321
Joined: Thu Jul 23, 2020 9:34 am

Re: A comples problem to explain...

Post by alex4orly »

Sounds logical
Bottom line is, that it doesn't work.

My solution can be useful for others, who like me want to determine which pages are frequented more, and by whom for planning reasons.

Cheers
Post Reply