tags:

views:

38

answers:

2

Hi I am doing my project in PHP.In this when the use**r doesnt logged in and click the photo then it display the message please login.Then **after login I wants, the user landing on the photopage..who clicked before login.How can I get the value of userclick and store it and how to redirect them to particular page?

A: 

It's not really a madder of what the user has clicked which anyway you don't have access to since it's on client side (apart using some ajax/javascript). You can know what URI/URL have been requested when you take the decision to redirect the user to the login page.

You have to stock in session ($_SESSION) the requested page. In your login page and when the user manage to login redirect him to the page stocked in session.

for example:

where you take the decision to redirect the user to the login page

if($foobar){
 $_SESSION['requested_page'] = $_SERVER['REQUEST_URI'];
 header('Location: login.php');
 die();
}

on the login page

if($loginOK){
  if(isset($_SESSION['requested_page'])){
    header('Location: ' . $_SESSION['requested_page']);
    die(); 
  }
  header('Location: /index.php');
  die();
}
RageZ
if the user doesnt click the photo then login I need to redirect him to the profile page.Whether previous method allowed that?
vinothkumar
@vinothkumar: can you edit your question to give more details on what you need ...
RageZ
A: 

This is usually handled with $_SERVER['HTTP_REFERER'] which will tell you where the user is coming from. Your log in page can then redirect back to it. (You don't need a session.)

mqsoh
what happen if the user type wrong password ?
RageZ
Then I suppose you would need a session. That doesn't make this worthy of a -1
Kevin Peno
If you had load balanced servers, a session might not work. I apologize, RageZ. A session is probably apropriate to this situation.
mqsoh