Returns the article tag with ID from the action page
Let's say you're in a login form and you enter the wrong information; in this case, you probably want to go back to the login page.
PHP has a built-in function header()
to redirect a page to a specific page.
But what if the login page is at the bottom of the page or somewhere in the middle.
In this case, we can locate the id of the tag and put it into the URL. We can use the Html article tag for the separate item part of the login form.
Use PHP headers to return a specific article tag with an ID
We use two different article tags with different ids, one with the content and one with the login form. When we submit, we want to go back to the login section.
index.php
page:
<!DOCTYPE html>
<html>
<head>
<style>
p {
font-size: 100px;
}
#email {
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
}
input[type=email], input[type=password] {
width: 100%;
padding: 10px 18px;
box-sizing: border-box;
margin: 8px 0;
display: inline-block;
border: 3px solid #8fbc8f ;
}
button {
background-color: #8fbc8f;
color: white;
margin: 8px 0;
cursor: pointer;
padding: 10px 18px;
border: none;
width: 100%;
}
</style>
</head>
<body>
<div id="main">
<article id="paragraph1">
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</P
</article>
<article id="email">
<form action="action.php" method="post">
Email: <input type="email" placeholder="example@example.com" >
<br>
Password: <input type="password" placeholder="********">
<br>
<button name="submit" type="submit" value="login" class="login">Login</button>
</form>
</article>
<article id="paragraph2">
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</P
</article>
</div>
</body>
</html>
Form operation page action.php
:
<script>
alert("This is form action page; please enter the information again, click ok to go back to the login form");
</script>
<?php
//header function is used to redirect the page to a perticular link. we can fetch the id of a tag and redirect the page
$url = 'Refresh:0; url=index.php#email';
header($url);
?>
After index.php
the form is submitted, the code will go to the second page and redirect it back to index.php
the login section of .
Output:
In this case, we can action.php
put anything before the header of the page to verify the email and password information in the database in order to redirect conditionally.
For dynamic redirection, we can index.php
use javascript or jquery on the page to get the id of the current tab and send it to action.php
to redirect the page to that tab.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Article URL:https://www.jiyik.com/en/xwzj/prolan_10688.html
Related Articles
Check if a Post exists in PHP
Publish Date:2025/04/13 Views:170 Category:PHP
-
PHP $_POST is a super global variable that can contain key-value pairs of HTML form data submitted through the post method. We will learn different ways to check $_POST if a and contains some data in this article. These methods will use iss
PHP with Ajax
Publish Date:2025/04/13 Views:139 Category:PHP
-
We will use PHP and ajax by printing a simple sum of two numbers 2 and . Also, print a php array in JSON. 3 object We will also use PHP with ajax by getting the HTML formatted output from the number division in PHP. Printing simple addition
Store Div Id in PHP variable and pass it to JavaScript
Publish Date:2025/04/13 Views:51 Category:PHP
-
This article shows you how to div id store a in a PHP variable and pass it to JavaScript code. We will answer the following questions. What is div id ? How to div id store in a PHP variable? How to pass variables to JavaScript code? Let’s
Switching PHP versions on Ubuntu
Publish Date:2025/04/13 Views:78 Category:PHP
-
Different tasks may require running multiple versions of PHP. You may need to switch PHP versions by running two sites on the same server or testing older versions of code using outdated methods. We can switch PHP versions on Ubuntu using t
Resizing images in PHP
Publish Date:2025/04/13 Views:155 Category:PHP
-
In this tutorial article, we will discuss about resizing images in PHP. Load the image before resizing Before we can resize an image, we must first load it as an image resource in our script. This is file_get_contents() different from using
PHP upload image
Publish Date:2025/04/13 Views:61 Category:PHP
-
We can upload images in PHP using simple file upload operation, but first, php.ini file upload should be enabled from Files. This tutorial demonstrates how to upload images in PHP. php.ini Enable file upload from file in PHP to upload image
Creating a signature from Hash_hmac() and Sha256 in PHP
Publish Date:2025/04/13 Views:107 Category:PHP
-
PHP has one of the best encryption functions for data security. Hash_hmac() The encrypt function is one of the most famous encryptors. We'll show you how to use hash_hmac and sha256 encryptors to create 安全签名 one that you can store i
Updating PHP 7.x to 7.4 on CentOS
Publish Date:2025/04/13 Views:131 Category:PHP
-
This article shows the steps to update the PHP version from 7.x version to 7.4 in CentOS. How to Update PHP from 7.X to 7.4 in CentOS Update operating system packages. yum update -y Check your PHP version in CentOS. php -v Prints a list of
Displays PHP configuration information on localhost
Publish Date:2025/04/13 Views:107 Category:PHP
-
phpinfo() is a built-in function in PHP which outputs all the information of PHP configuration on the local host. We have to phpinfo() create a PHP file with a simple function call. Sometimes, the file may not work properly and output a 404