0

In my html I currently have:

 <input type="hidden" name="redirect" value="example.com" />

Is it possible to change the value to redirect to the current page (basically refreshing the page) without having to manually put the url in for each page?

2 Answers2

0

Yes, you could add this function to your code. I use it in some of my application

create a function like :

function getPageUrlNoQuery()
{
    $pageUrl = ($_SERVER['PHP_SELF']);
    return $pageUrl;
}

include the function file, and call.

<input type="hidden" name="redirect" value="<?php echo getPageUrlNoQuery() ?>" />

Have edited, and i think this should work in most architecture as long as you can call the function, or class. whichever you use.

SourceOverflow
  • 1,960
  • 1
  • 8
  • 22
Maccabeus
  • 89
  • 1
  • 6
  • 1
    1. He didn't want it in the `
    ` attribute. 2. That may not work in every architecture, if I understand the way it works correctly.
    – SourceOverflow Oct 09 '17 at 11:22
  • @SourceOverflow yeah, u are right. Get i was sleepy when i posted that. intend to use the input tag. – Maccabeus Oct 09 '17 at 14:45
0

Well, in PHP you should know what page you are loading anyways and then put that value in. (I don't know your architecture, but either set a variable in your controller manually or if you don't use Controllers, then simply extract the URL from the get request.)

Alternatively you can use Javascript:

document.getElementById('YourLink').value = window.location.href;
SourceOverflow
  • 1,960
  • 1
  • 8
  • 22