Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Storing URL parameters in a PHP session variable [done]

Post your ideas & suggestions for new nuBuilder features or other improvements
Post Reply
nac
Posts: 115
Joined: Tue Dec 12, 2017 11:28 pm
Location: Aberdeen, UK
Has thanked: 9 times
Been thanked: 12 times

Storing URL parameters in a PHP session variable [done]

Unread post by nac »

I have recently wanted to use some custom parameters passed via the login URL. I propose storing these as a PHP session variable which is created when the $_GET array is parsed in index.php. My request then is to add these three lines near line 229 in index.php (after the built-in Auto Login parameters have been assigned to variables). In my example, the password parameter would be removed from the stored array.

Code: Select all

	
$nuHome = $_GET['h'] ?? '';

// store the parameters for the duration of the session
$URLParams = $_GET;
unset($URLParams['p']);  // remove the password from the array
$_SESSION['nubuilder_session_data']['URL_PARAMS'] =  $URLParams;
// end of parameter storage insert

I realise that there are methods in both JavaScript and PHP to achieve this, but a little experimentation has convinced me this would be the simplest and most reliable solution.

Thanks

Neil
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Storing URL parameters in a PHP session variable

Unread post by kev1n »

Hi Neil,

Thanks for your suggestion!

The code within index.php can also be executed at a later time, such as when an iframe is loaded. Therefore, it would be prudent to conditionally set the URL_PARAMS only if they have not been defined already. Failing to do so could lead to potential difficulties in retrieving them later.

Code: Select all

	$URLParams = $_GET;
	unset($URLParams['p']);
	if (!isset($_SESSION['nubuilder_session_data']['URL_PARAMS'])) {
		$_SESSION['nubuilder_session_data']['URL_PARAMS'] = $URLParams;
	}
The parameters can be retrieved with nuGetURLParams(). Update is on Github, please test.
nac
Posts: 115
Joined: Tue Dec 12, 2017 11:28 pm
Location: Aberdeen, UK
Has thanked: 9 times
Been thanked: 12 times

Re: Storing URL parameters in a PHP session variable

Unread post by nac »

Thanks Kevin,
That all makes sense. I will test it and let you know ASAP.
Neil
nac
Posts: 115
Joined: Tue Dec 12, 2017 11:28 pm
Location: Aberdeen, UK
Has thanked: 9 times
Been thanked: 12 times

Re: Storing URL parameters in a PHP session variable

Unread post by nac »

Hi Kevin,
On the basis of tests done so far, this code is fine and working exactly as expected.
Thanks
Neil
Post Reply