Session variables NOT WAPPLER

I have an old website, that is not on Wappler yet, sadly. i need to make a few changes and need to use a session variable to pass information from page to page, and for the life of me i can not get it to work, but it should.

Page A

<?php 
	session_start();
	$_SESSION["themeSwitching"]="IOC";
	echo $_SESSION["themeSwitching"];
?>

Page B

<?php 
	session_start();
	echo $_SESSION["themeSwitching"];
?>

When i switch between PageA to PageB i would expect it to still echo IOC on PageB, but it just shows nothing. I am super confused.

I know it is not a Wappler question, but honestly 3 days later, I am just trying anything now.

Nothing wrong with the code. You have placed the code in a PHP document?

1 Like

Yes, its in a php document, only thing i can even thing of may possibly be that there is some php.ini configuration at the hosting provider stopping the passing along of the values?
I have also tried it in a few different browsers to make sure it was not some browser security stopping it, but Chrome, Safari and Firefox all show the same.

Create two new documents containing just the PHP scripts and see if that works for the site.

try splitting the code.
session_start needs to be executed before any html. put it at the very start of the page, even before doc type etc however as this is outside the document the echo will not appear so place that within the body

Will try both yours and bens solutions in just a bit, of course, i saw Bens idea, went and loaded the website and got a page like this


I mean, of course the certificate expired today, it just seems like the right thing to do, so now i am fighting with getting a new certificate installed which is just giving error after error. Sometimes i wonder how anybody does this web rubbish lol

So true, I have said "sod this, I am retiring’ so many times over the lsst 5 years. Actualky did that once then some sod developed this thing called Wappler and i got hooked again.

2 Likes

haha haha, lets blame all this on George, at least we have a way of getting hold of him.

@George, could you please make an email address of george@madetheinternet.com so we can all email you with our internet related complaints.

2 Likes

OK, thank you @Ben and @Hyperbytes, I took Ben’s suggestion and just placed the code all by itself on a new page and all worked exactly as expected, checked my other pages that were not working before and they were still not working.

Moved the script to line 1 of the document, before any other script ran and now everything is working. I am not sure how but if this line of code is placed above the session code it breaks it.

<?php if (substr_count($_SERVER[‘HTTP_ACCEPT_ENCODING’], ‘gzip’)) ob_start(“ob_gzhandler”); else ob_start(); ?>

To be honest it does not really matter why either, because it works now, so if anyone knows why, it is just more for my own curiosity in my little fact finding mission.

Thanks Wappler, for fixing my non Wappler problems too, haha.

Sessions need to be initialised before any HTML output or the initialisation fails, it must always be the first thing on the page

1 Like

Ahh, ok, I thought as long as i declared session_start before the session then it could be somewhere else. Thanks for letting me know, love knowledge.

I do it literally as the first thing on the page, actually before doctype as I have known even that to break it. Anything that outputs any type of headers must come after
LIke this:

	session_start();
	
	if(!isset($_SESSION['cart_session'])) {
			$_SESSION['cart_session'] = session_id();
	}
?>
<!doctype html>
<html><head>
2 Likes