dongzhu6900 2014-05-21 19:45
浏览 36
已采纳

如何从HTML调用字符串到2个单独的PHP?

I have log-in page, now I want to use the username input for two separate PHPs. how can I do it?

<form method = "post" action="login.php">
    <input type = "hidden" name = "submitted" value = "true"/>
    <h1>НЭВТРЭХ</h1>
    <div>
        <input type="text" placeholder="Student ID" required="" id="username" name="username"/>
    </div>
    <div>
        <input type="password" placeholder="Password" required="" id="password" name="password"/>
    </div>
    <div>
        <input id="button" type="submit" name="submit" value="НЭВТРЭХ" />
        <a href="#">Lost your password?</a>
    </div>
</form><!-- form -->

The login.php is the first php calling the string. this php gets the string and works fine. but i want to use this string for another PHP.

  • 写回答

2条回答 默认 最新

  • drcvvkx914772 2014-05-21 20:21
    关注

    In your login.php file you do something like this:

    <?php
    // Start the session engine for this php file
    session_start();
    
    // Might want to add more validation to those variables before using them
    if(isset($_POST['username']) && isset($_POST['password']))
    {
       $_SESSION['username'] = $_POST['username'];
       $_SESSION['password'] = $_POST['password'];
    } 
    
    ?>
    

    and then you can access those $_SESSION variables from the other php file.

    See W3School for more info on sessions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?