0

I was wondering if this is even possible... I am working on this flow

A user is on "ask-now" (http://domain.com/ask-now/) page and click "ask" link, he will be redirected to "redirect.php" and "redirect.php" will redirect to answer.php but the URL of answer.php must carry the full url of http://domain.com/ask-now/ Like this form http://domain.com/answer.php/?ask=http://domain.com/ask-now/

and everytime user click "ask" on any webpage on my website they will always redirected to http://domain.com/answer.php/?ask=( THE FULL PATH URL WHERE THEY CAME FROM ).

Can someone help me please? :)


FLOW UPDATE as Kumar requested. Thanks for the help buddy.

Detailed Version

I have a website http://domain.com/. The website has lot of pages http://domain.com/page1/ --- http://domain.com/(and son on) LOT! Each of the page has a anchor text "ASK" which is link to http://domain.com/redirect.phpand redirect.phpwill redirect to http://domain.com/answer.php.

What I want is the http://domain.com/answer.php will carry the full path url of the previous page where the user came from. and show the url like this http://domain.com/answer.php/?ask=(THE FULL PATH WHERE THE USER CAME FROM) .

Example: The user is from http://domain.com/page100/ and he click the link ask which is redirected to answer.php now, he is now on answer.php page and he will see the full url above is http://domain.com/answer.php/?ask=http://domain.com/page100/

I think I have explained very well..

Thank you Kumar. Hope you can solve this!

james
  • 73
  • 1
  • 9
  • You have to make changes in .htaccess file, go through this link http://stackoverflow.com/questions/11149526/symfony2-rewrite-rules-htaccess-app-php – M Gaidhane Nov 16 '13 at 09:07

2 Answers2

0

in redirect.php add this logic

if($_SERVER["HTTP_REFERER"]=="http://domain.com/ask-now/"){
    $location="http://domain.com/answer.php/?ask=".$_SERVER["HTTP_REFERER"];
    header("Location: $location");
}

You can change your logic according to your requirement.

  • Hello Kumar Thanks for the response but can you please write the whole redirect.php ? i do not know where to add the code you provided.... I have a very basic redirect script i got from searching... Also I was wondering if the code you provided is working also on other pages on my wordpress site. I am skeptic on this one `if($_SERVER["HTTP_REFERER"]=="http://domain.com/ask-now/"){ ` I think works only on `http://domain.com/ask-now page` – james Nov 16 '13 at 09:20
  • I updated it. Please check above. Thanks Kumar hope you can solve it :) – james Nov 16 '13 at 18:10
0

Simply save the current users' page to COOKIE or his SESSION, and get it later. I suggest this way because HTTP_REFERER is not always transmitted.

For example:

  1. User visits http://domain.com/ask-now/, php-script sets cookie, which saves currrent page url. After that it goes redirect to the answer.php:

setcookie('ask_page', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"], time() + 3600, /'); header("Location: /answer.php");

  1. At the answer.php you will get the previous page from cookie:

echo $_COOKIE['ask_page'];

Dmitry Seleznev
  • 955
  • 7
  • 7
  • Hello Dmitry, can you please elaborate more how this work? together with the code please? i'm really new to this stuff. – james Nov 16 '13 at 09:52
  • thanks very much dmitrtry, however i still don't get it. where to put that setcookie stuff? Thanks every one... perhaps i really need to hire someone on this kind of stuff... thanks for the effort. I appreciate it. – james Nov 16 '13 at 12:08