开发者

let jquery know which was the last visited php page?

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开发者_JAVA技巧 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.


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


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"]);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜