0

I hope these lines would explain the question:


//in javascript
function foo(sessionName){
    var u = "test.php?q="+sessionName+"&r="+parseInt(Math.random()*9999999);
    xmlHttpObj.open("get", u, true);
    xmlHttpObj.send();
}       

//in php

$q = $_GET['q'];
unset($_SESSION[$q]);

Like you see, I don't want any value returned, I just want to unset the specific session.

4
  • 1
    So what's the problem? Just don't handle the return Commented Apr 18, 2011 at 5:52
  • This doesn't make any sense...I don't even know how to suggest an improvement. Commented Apr 18, 2011 at 5:53
  • you can't, ajax will erase the original value if you don't return any value, it's like returning echo""; Commented Apr 18, 2011 at 5:56
  • Sorry, "ajax will erase the original value" doesn't make sense. What's the concrete problem you're experiencing? Commented Apr 18, 2011 at 6:11

3 Answers 3

2

You don't ever have to return a value, if you access and run the script it will do it's job. The problem will be that you will have no way of knowing if it succeeded, so it's best to return a success/failure value in general. However, since unset() doesn't actually return a value there is no need in this case.

Sign up to request clarification or add additional context in comments.

1 Comment

This is assuming typos rather than actual errors in your example :)
1

Yes, this works. I suppose your problem is a typo in the variable name?

var u = "test.php?q="+sessionName+"&r="+parseInt(Math.random()*9999999);
                  ^
$n = $_GET['n'];
            ^

2 Comments

just ignore if there's a typo, how to return nothing?
@Bagong Just... don't return anything. Looks like you're already doing just that.
0

It is probably better to still return a value indicating wether it worked or not. Even though this code should work just fine.

Adding this to the end of your script will give you an indicator wether it worked or not.

if (isset($_SESSION[$n])) {
    echo 'success';
}
else {
    echo 'fail';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.