/    Sign up×
Community /Pin to ProfileBookmark

Session handlig via AJAX. Please Help!

I need to create a session variable via ajax. Below are the two files that I’m using.
Both are calling via ajax.

I used this file to create sessions or cookies.
First i try to create sessions or cookies with this script.

[code=php]
<?php
session_start();

$stateIdVal = $_POST[‘stateIdVal’];
$rememberMe = $_POST[‘rememberMe’];

if($rememberMe)
{
$_COOKIE[“searchCriteriaState”] = $stateIdVal;
}
else
$_SESSION[“searchCriteriaState”] = $stateIdVal;

echo “1”;
?>
[/code]

And this to retrieve session variables. (Try to get the session values previously created)

[code=php]
<?php
session_start();

$return_str = “”;

if(isset($_COOKIE[“searchCriteriaState”]))
{
$return_str .= $_COOKIE[“searchCriteriaState”];
}
elseif (isset($_SESSION[“searchCriteriaState”]))
{
$return_str .= $_SESSION[“searchCriteriaState”];
}
else
$return_str .= “null”;
echo $return_str;
?>
[/code]

But it’s not working. I’m hanging on this about days, and bored on this.

Please anyone help!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@DokSep 07.2008 — I don't understand. Sessions/cookies are not handled differently using Ajax. Its like any other HTTP reuqest. Why are you explicitely setting variables in cookies? PHP can take care of all of this for you...
Copy linkTweet thisAlerts:
@UI-ZEIKVKauthorSep 08.2008 — Thanks for the reply,

I need to create these for a website menu. And need to remember the menu criteria if user needed. That's why i create cookies.

Anyway this is not working. Why?
×

Success!

Help @UI-ZEIKVK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...