How manage session between three page in php.

PHP
do you want user visit first page then and then go second. user can't go directly on secong page using web URL. e.g. login validation required for future process.



below i written three php file and creating session between this file .

first page index.php

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        session_start();


        if ($_SESSION['name'] != "$name") {
            $currentvalue = $_SESSION['name'];

            header("location:$currentvalue.php");
        } else {
            ?>
            <form action="" method="post" name="ind">
                <input type="submit" name="next" value="first">
            </form>
            <?php
            if (isset($_POST['next'])) {
                $_SESSION['name'] = "second";
                header('location:second.php');
            }
        }
        ?>

    </body>
</html>


second page second.php

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        session_start();

        if ($_SESSION['name'] != "second") {
            $currentvalue = $_SESSION['name'];
            header("location:$currentvalue.php");
        } else {
            ?>
            <form action="" method="post" name="ind">
                <input type="submit" name="next" value="next1">
            </form>
            <?php
            if (isset($_POST['next'])) {
                $_SESSION['name'] = "third";
                header('location:third.php');
            }
        }
        ?>

    </body>



third page third.php





<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        session_start();

        if ($_SESSION['name'] != "third") {

            $currentvalue = $_SESSION['name'];
            header("location:$currentvalue.php");
        } else {
            echo 'third page';
        }
        ?>

    </body>
</html>
 

Comments

Popular posts from this blog

How can I debug PHP cURL sessions?

[PHP] Create MySQL Trigger in PHP

Free icons