General |  Social Media |  Miscellaneous
Login
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ ghhjhjh ☛ Don't mess with health, let's know some important things related to health ☛ How was Shani Dev born and how was his vision crooked? ☛ Story of creation of man, hunger and thirst? ☛ Why is it advised to eat garlic on an empty stomach? ☛ Indian Culture: Wisdom of sages ☛ Untold Story: Last debt pyre wood ☛ Wooden Bowl: The Moral Story ☛ A great story of value of experience ☛ These fourteen types of people are like dead on earth 
Home > Innovation & Technology > PHP

How to redirect to another page in php after submit


how to redirect a url? or how to redirect a page to another page? It is basic requirements of any website that was made in PHP or other languages. Today Redirection is an essential part of recent website. In redirection, you can actually divert your user to a particular page of your website.

For example, If user is working on your website and user wants to submit a comment or logged in/logged out on your website, then you should have to redirect to thank you page or user profile page if user wants to logged in.

PHP provides a simple and clean way to redirect visitors to another page.

Now in PHP, redirection is done by two types.

  1. Using header() function
  2. Using <meta http-equiv="refresh" content="0;url=http://www.google.com/" />

 

PHP code to redirect page:

  1. Create HTML code for sending information to server

<!DOCTYPE html>

<html>

<head>

    <title>Title of page</title>

</head>

<body>

 

    <form action="contact.php" method="POST">

        <input type="text" name="name">

       <input type="text" name="email">

        <textarea name="message"></textarea>

        <input type="submit" name=”submit” value="submit"> 

    </form>  

</body>

</html>

 

  1. Create PHP code for giving response of HTML form

<?php

If(isset($_POST['submit'])) {

    if($_SERVER['REQUEST_METHOD'] == 'POST') {

       

        $name = $_POST['name'];

        $email = $_POST['email'];

                  $message = $_POST['message'];

       

        if($name && $email && $message) {

            header('location: thankyou.html');

           //or below types

           echo '<meta http-equiv="refresh" content="0;url=http://www.google.com/" />'

        }

    }

}

?>

 

  1. HTML code for thank you page

<!DOCTYPE html>

<html>

<head>

    <title>Page Title</title>

</head>

<body>

 

    <p>Thank you!</p>

 

</body>

</html>

This is a simple PHP script for redirection one page to another page. Firstly we have sent input values like name, email and message by html form tag after that we used PHP script for checking and retrieving input fields value through POST method, which is only possible if we submit the form.

Written By: Charles Miller Published in PHP


Search

Publish your passions on srcraftblog.com

Latest Post

☛ Don't mess with health, let's know some important things related to health

☛ How was Shani Dev born and how was his vision crooked?

☛ Story of creation of man, hunger and thirst?

☛ Why is it advised to eat garlic on an empty stomach?

☛ Indian Culture: Wisdom of sages

☛ Untold Story: Last debt pyre wood

☛ Wooden Bowl: The Moral Story

☛ A great story of value of experience

☛ These fourteen types of people are like dead on earth

☛ 33 crores or 33 koti Hindu deities?


We are accepting well-written informative Guest Posts on srcraftblog.com

Innovation & Technology

Artificial Intelligent blogs
Cryptocurrency blogs
Digital India blogs
Data science blogs
Neuroscience blogs
Programming blogs

Physical science

Physics blogs
Chemistry blogs
Earth science blogs
Geology blogs
Oceanography blogs
Meteorology blogs

Industry

Business blogs
Economy blogs
Freelancing blogs
Leadership blogs
Productivity blogs
Work blogs

Society

Basic income blogs
Education blogs
Environment blogs
Media blogs
Philosophy blogs
Women blogs
About us |  Write for us |  Terms and conditions |  Contact us

© 2023 SRCRAFT INIDA