Let's look at how to go to the previous page in PHP.
There is, of course, a way to go back to the previous page in JavaScript.
JavaScript has a history built-in object, and there's a back() or go() function that saves the previous page information.
But is it possible to go to the previous page in PHP and server language?
This is also possible and you can go back using the information on the previous page.
※ How to go to the previous page of PHP
The first thing you need to know is that in order for the server to be able to move the page, there is no output on the web page. In other words, if there is no output to the browser, you can move and you need the following built-in variables to refer to the variable where the address of the previous page is stored.
$_SERVER['HTTP_REFERER'] |
With these keywords, you can retrieve the page address just before you visit the current page. Save the loaded page to a variable and use location to move the page. See the example below.
※ Return to previous page View sample source code
Below is a simple example to go to the previous page.
After saving the information of the previous page in the variable $prevPage, use header() to move it.
<? php
$prevPage = $_SERVER ['HTTP_REFERER'];
// Store previous page information in a variable
header('location:'. $prevPage);
// Move page
?>
It is now very easy to go back to the previous page. What if this code is used in JavaScript? It should look something like this:
<script>
history.back();
</script>
Here's how to go to the previous page.
'개발 꿀팁 > PHP' 카테고리의 다른 글
[PHP function] URL page image tag extraction (0) | 2018.01.16 |
---|---|
Remove empty elements from PHP array (0) | 2018.01.16 |
How to check data types in PHP, Gettype() (0) | 2018.01.16 |
[PHP] Removing duplicate values in arrays, Array_unique () (0) | 2018.01.16 |
How to import Amazon product descriptions, images, etc. with ASIN [Using AMAZON ASSOCIATES] (0) | 2018.01.16 |