php - Making page that user is viewing stay on page rather than redirecting to home page -


using php, how able accomplish this? ex:

1.) there total of let's 5 pages (a, b, c, d, e) user can view (either logged in or out)

2.) user x viewing page (c) , not logged in

3.) user x logs in on page (c) , logged same page (c) he/she viewing rather being redirected home page

i know how make user redirected home page when user logs in on page, not desire , users not want - user can log in on whatever page viewing , stays on page them rather being redirected.

this have user login , redirected with, have no idea how make work users being able stay on whatever page user viewing when login.

php

header("location: index.php"); 

is there more needed allow users stay on same page viewing when login? or there simple solution can't seem find using 1 line of code above?

i've read tons of tutorials/blogs/forums, etc...but couldn't find definite answer anywhere. did come across 'php_self' have no idea how implement @ , php.net doesn't have clear solution how use - (or @ least read)...any appreciated.

solved: --> thank thinkswan

$current_url = "http://$_server[http_host]$_server[request_uri]"; header("location: $current_url"); 

update: --> question stems initial question

from provided above correct format, possibly take bit further? example:

same rules apply mentioned.

1.) if user x not logged in on page (c), , let's page (c's) url reads http://www.example.com/members.php, , there div container he/she clicks on page, bigger div container opens.

2.) of url reads http://www.example.com/members.php#registered_members

3.) while open, user x decides log in. there way make once user x logs in stays on same page bigger div container open? of right now, div container collapses once user x logs in, logged in on same page.

you can make use of $_server['request_uri'].

example:

$current_url = "http://$_server[http_host]$_server[request_uri]"; header("location: $current_url"); 

answer revised question:

the #registered_members part of url, known fragment identifier, never sent server—it client-side only. php never aware exists.

you can, however, check javascript when page reloads , update page based on whether it's present or not.

<script>alert(window.location.hash);</script> 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -