General |  Social Media |  Miscellaneous
Login | Register
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ True Story of Beggar: Punishment for the deeds done by us ☛ India: The Story of a Joint Family ☛ AI Driven Analytics | Life Sciences Data Analytics | WhizAI ☛ The Story of Gurukul: Test of intelligence ☛ The Problem Solving Skills ☛ Eternal law that never changes ☛ After all, why does Mahadev apply ashes on the body? ☛ Kitchen Worktops Buy now | Grey Worktops on sale ☛ Black Kitchen Worktops on Sale in UK ☛ White Kitchen Laminated Worktops Buy in UK 
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

☛ True Story of Beggar: Punishment for the deeds done by us

☛ India: The Story of a Joint Family

☛ AI Driven Analytics | Life Sciences Data Analytics | WhizAI

☛ The Story of Gurukul: Test of intelligence

☛ The Problem Solving Skills

☛ Eternal law that never changes

☛ After all, why does Mahadev apply ashes on the body?

☛ How to get an e-pass for curfew in Delhi, know the complete process in 6 easy steps

☛ 10 TIPS TO QUICKLY CLEAN YOUR JEWELLERY

☛ Quartz Worktops: Better Choice for Many People


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

© 2022 SRCRAFT INIDA