Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.