General |  Social Media |  Miscellaneous
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Best Europe cities to travel with Toddlers ☛ Make Your Limousine Ride Even More Special: 10 Top Ideas ☛ Leverage SEO Services to Secure Success for Your Storage Company ☛ Telerehab physical therapy : healing at your fingertips ☛ 10 Best Activities in India for Thrills and Relaxation ☛ Wedding Limos That Redefine Luxury Transportation ☛ Flying with Family: A Guide to Kid-Friendly Travel from Calgary to Kelowna ☛ How To Protect Your Privacy Online? [Complete Guide] ☛ Help and kindness is the biggest religion ☛ Burning bamboo wood is prohibited in the scriptures, Why 
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

☛ Best Europe cities to travel with Toddlers

☛ Make Your Limousine Ride Even More Special: 10 Top Ideas

☛ Leverage SEO Services to Secure Success for Your Storage Company

☛ Telerehab physical therapy : healing at your fingertips

☛ 10 Best Activities in India for Thrills and Relaxation

☛ Wedding Limos That Redefine Luxury Transportation

☛ Flying with Family: A Guide to Kid-Friendly Travel from Calgary to Kelowna

☛ How To Protect Your Privacy Online? [Complete Guide]

☛ Help and kindness is the biggest religion

☛ Burning bamboo wood is prohibited in the scriptures, Why


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