Storing redirect URLs for future reference

I am trying to save a redirect URL for use on several pages later, but it is difficult for me to figure out how to get it from one place to another.

Usually I just passed the variable through the url, but since the redirect url contains url variables, this does not work.

To give you a better idea of ​​what I'm trying to do, here is the structure.

PAGE 1: User can click the link to add content on the page PAGE 2

PAGE 2: User enters text. Submitting a form on this page calls "formubmit.php", where MySQL data records are processed. At the end of this, I need to redirect the user to PAGE 1 again. The redirect URL must exactly match what was originally on page PAGE 1

Does anyone have any suggestions on this?

+5
source share
5 answers

$_SESSION . , , ( , , , .. ..), $_SESSION / , .

, - :

$_SESSION['redirUrl'] = "http://www.lolthisisaurl.com/lolagain";

, ,

$theUrl = $_SESSION['redirUrl'];

, : http://php.net/manual/en/reserved.variables.session.php

+6

, URL- . ; ( , ), $_SESSION var:

<?php

session_start();
...
$_SESSION['redirect_url'] = whatever.com;
...

, . , URL- :

<input type='hidden' name='redirect_url' value='<?php echo $redirect_url; ?>';

URL $_POST $_GET ( , ) .

+2

urlencode urldecode , , URL- url.

+1

:

Hi,

Max

+1
source

You can add this hidden field to your form:

<input type="hidden" name="referer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>">

Then use header()to redirect to this page:

header('Location: '. $_POST['referer']);
+1
source

All Articles