views:

87

answers:

4

this is a little bit tricky.

usually when someone clicks on a link that requires him to register, this person will be redirected to the registration page and then back to the last visited page. this is possible cause the link sent a GET key through the url to the registration.php which uses the key to go back to last visited page.

but i intend to use jquery ajax for registration. basically ive got 3 different php pages. all of them include the same header.php. and in header.php ive got a registration button which i have id tagged. when this button is clicked ( $(#registration_button).click()... ) jquery will show a box (a div that was hidden in the center of the browser) with registration information. then he will register and i will redirect him to the last visited page, that is to say the current one he sees. i have to refresh the php-page to be able to show all links that a registered user can see, thats why i have to use window.location.href.

now to the question. how do i let jquery know which page is the current one he is visiting? ive got 3 php-pages.

if there is something you dont understand, please free to ask. or if you got suggestions of other solutions, let me know. but i really want to display the registration box right away without redirecting him to another page.

A: 

You could assign the page to a session and do it that way.

$_SESSION["page_visited"] = "x.php";

Make sure to use session_start on the pages using sessions. Then just redirect to the relevant page.

header('Location: http://www.example.com/'$_SESSION["page_visited"]);
Gazler
but then i have to set a session every time a page loads. isnt that killing performance? can jquery/javascript read a session or cookie set by php. or do i have to use ajax -> php-file to check it?
never_had_a_name
+1  A: 

You can set cookies initially in php and then update/read them via js.

Jacob Relkin
A: 

use Cookie Plugin for jQuery

luckykind
where is the documentation?
never_had_a_name
examples are right there at the top of the download... I've used it for the same reasons you described above... needed to know last position in js after a php page reload... it works
luckykind
A: 

I did a similar thing not two weeks ago, correct me if I'm wrong, but if you want the registration to direct to the page the user was on, after the user has been registered in the ajax just add:

window.location.href=window.location.href;

That way the after the registration is done, it just reloads where the member was with the environment of a logged in user. This method worked great for me.

Sam152