douqi1928 2013-05-03 04:37
浏览 22

PHP会话问题

I'm using sessions to save what ever the user types in the form and what ever they do type will be displayed on the other pages.

It was working perfectly fine but after all the server uploads and such my code has completely done one on me and i'm lost.

Can somebody see if they can spot a mistake? I need fresh eyes.

HTML.

    <div id="form"><!--Form Start-->

<form action="home.php" method="post">

    <p>Enter Name <input type="text" id="full_name" name="fullName"    class="name_input"/>

<input type="submit" name="submit"  value="Submit" />

</p>

    </form>

    </div><!--Form end-->

PHP.

    <?php
session_start(); // declaring the variable

if(isset($_POST['fullName'])){ //setting the variable 

    if(empty($_POST['fullName'])){ //if empty dont to nothing but my wep page will reload

    }else{ //if they have do this

        $_SESSION['fullName'] = $_POST['fullName']; //get the session for the name (From the from)


        header("Location: home.php"); //then will direct the user to the home page (will also display name on each page)
    }}
    ?>

Session on other pages

                  <div id="echo"> <!-- div ECHO start -->           
                                  <?php


                   echo $_SESSION['fullName']
             ?>                  
            </div>  <!--div ECHO end -->    
  • 写回答

5条回答 默认 最新

  • douxu2081 2013-05-03 04:42
    关注

    You need to start session on other page as well and stop the script from setting that session. After header location you need to use exit here.

     <?php session_start();?>
      <div id="echo"> <!-- div ECHO start -->           
      <?php
         echo $_SESSION['fullName'];
       ?>      
    

    you need use exit after header location :-

     header('location: home.php');
     exit;         
    
    评论

报告相同问题?