Jump to content

[SOLVED] sessions


zang8027

Recommended Posts

What I am trying to do is when the session "cart" is created, create a constant with it. If it is already created, then the constant is already set, so use what is set. These constants will only be deleted when the user closes the site. Here is my code

 

<?php

// TESTING OUT CONSTANTS ******************
$restID = $_REQUEST['restId'];

if(! isset($_SESSION['cart']))
{
	$_CONSTANTS['restaurant'] = $restID;
	foreach($_CONSTANTS as $key => $val)
    			define($key, $val);
	$myConst = constant('restaurant');
}else{
	$myConst = constant('restaurant');
}

?>

 

 

Now, first time I go to the site, everything is fine. But once i refresh the page, it says it can not find the constant. Why can't it find it? It is supposed to be global.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/143633-solved-sessions/
Share on other sites

im trying to use a new session now.

 

<?php
                $_CONSTANTS['restaurant'] = $restID;

	foreach($_CONSTANTS as $key => $val)
    			define($key, $val);

	$myConstant = constant('restaurant');
	$_SESSION['rest'] = $myConstant; //now session 'rest' is equal to my constant value

}else{


}

 

 

Now I want to set that session to a variable if possible to reference. Is that possible? See, I am using the value of this session to be passed to functions and pull information out of a database. Can i just pass a session through a function?

 

function name($_SESSION['cart']) ???

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/143633-solved-sessions/#findComment-753678
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.