using php sessions in an API
Moderator: General Moderators
using php sessions in an API
is it possible to set and pass session variables through an API? The API in question simpy receives variables by $_GET. I thought perhaps i could set the session variables by way of the $_GET variables in the url. The return of the API is always simple XML. All this is for a flash site i am working with...after a user logs on, we want to be able to utilize that username by way of sessions. However, i am not having much luck passing that variable onward....much less get re-usablity of the variable. Before i blast you with code, is this possible?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php sessions in an API
$_GET and $_SESSION are two different way to make values available to scripts. You can certainly set session variables from GET values (after proper security meansure
) as well as passing values in the session as parameters.
(#10850)
Re: using php sessions in an API
hmmm...so after the initial session variable is set, i should be able to pass it around on multiple queries....i guess i need to check over my code
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php sessions in an API
Once you assign a variable to the session, you do not need to pass it around. That is the whole point of sessions.
(#10850)
Re: using php sessions in an API
k- tail between my legs, let's find out what i don't know about sessions.
so, if i put in website.com?name=myname
i should see myname
and if next i remove the ?name=myname, should it still not still echo myname?
Code: Select all
<?php
session_start();
session_id('ti');
if(! isset($_SESSION['name']))
{
if(isset($_GET['name']))
{
$_SESSION['name'] = $_GET['name'];
}else
{
$_SESSION['name'] = $_SESSION['name'];
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test</title>
<meta name="generator" content="BBEdit 8.7">
</head>
<body>
<?php echo $_SESSION['name']; ?>
</body>
</html>
i should see myname
and if next i remove the ?name=myname, should it still not still echo myname?