会话没有在页面之间传送

时间:2013-03-15 13:30:59

标签: php html json forms session

我在这里创建了一个登录页面是代码,我没有使用任何数据库,我应该携带登录用户的电子邮件,直到它登出,这是我的登录页面(login.php)。 在表单操作中我用一些键调用了一个Web服务,我把它变成了json格式,然后在发送到服务器时我得到一个json格式的响应,它被解码并在检查了一些条件后(所有这些都发生在配置文件中)。 php)根据条件的响应将它们重定向到另一个页面,检查它被重定向的页面是(pipm.php)。

login.php是

<?php 
    session_start();
    ?>
    <html>
    <head>
    <title>LOGIN FOR PRODUCT MANAGEMENT</title>
    <link href="style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
    <div id="contact">
    <form id="myForm1" action="profile.php" method="post">
    <div style="margin-left:180px;color:#445668">
    <h3>LOGIN</h3></div> 
    <p>
    <div style="margin-left:10px;margin-top:10px;">
    <label for="username">Email</label>
    </div>
    <div style="margin-top:10px;">
    <input type="email" id="username" name="username" placeholder="Enter your username"/>
    </div>
    <div style="margin-left:10px;margin-top:10px;">
    <label for="password">Password</label></div>
    <div style="margin-top:10px;">
    <input type="password" id="password" name="password" placeholder="Enter your password"/>
    </div>
    <div style="margin-top:20px;margin-left:-30px;width: 185px;text-align: right; font-size: 12px; color: #445668; 
    text-transform: uppercase; text-shadow: 0px 1px 0px #f2f2f2;"><a href="forgotpass.php" style="text-decoration:none;">Forgot Password?</label></a>
                <div style="margin-left:440px;margin-top:-20px;"><input type="submit" name="Submit" value="Send "/></div>
     </p>
     </form>
     </div>


<?php
$temp=$_SESSION['username'];
echo "$temp";
if (isset($_POST['Submit'])) { 
 $_SESSION['username'] = $_POST['username'];
 } 
?> 
  </body>
</html>

profile.php是

<?php
session_start();
$usernamepm = $_POST['username'];
$passwordpm =$_POST['password'];
$loginpm=array(
'user_name'=> "$usernamepm" ,
'password' => "$passwordpm"
);
$url='http://192.168.2.31:8080/Product_Deployment/services/user/login';
        $data="$loginpm";
        $ch=curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginpm));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
        $response=  curl_exec($ch);
        curl_close($ch);
        $jsondepm = "$response";
        $jsonde_o= json_decode($jsondepm);
        $jsonde_a=json_decode($jsondepm,true);
        $loginstatus=$jsonde_a[firsttimelogin];
        if($loginstatus=="yes")
        {  
        header("Location:pipm.php");
        }
        if($loginstatus=="no") 
        {
        header("Location:pipm.php");
        }
        if($loginstatus=="")
        {
        header("Location:login.php");
        }


?>

pipm.php是

<?php
session_start();
?>
<html>
<head><title>PERSONAL INFO COLLECTION PAGE</title>
<link href="pipm.css" rel="stylesheet" type="text/css"/> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script>
   function onKeyPressBlockNumbers(e)
{
    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    reg = /\d/;
    return !reg.test(keychar);
}
 function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }   
$(function() { 
    $("#datepicker1").datepicker({ dateFormat: 'yy-mm-dd' });
});

    function validate()
{
    var vfname=trim(document.frm.fname.value);
    var vlname=trim(document.frm.lname.value);
    var vdatepicker1=trim(document.frm.datepicker1.value);
    var vmobile=trim(document.frm.mobile.value);
    var vaddressline1=trim(document.frm.addressline1.value);
    var vaddressline2=trim(document.frm.addressline2.value);
    var vaddressline3=trim(document.frm.addressline3.value);
    var vcountry=trim(document.frm.country.value);
    var vstate=trim(document.frm.state.value);
    var vcity=trim(document.frm.city.value);
    var vpin=trim(document.frm.pin.value);
    var vcompanyname=trim(document.frm.companyname.value);
    var vwebsite=trim(document.frm.website.value);
    var vcompanyemail=trim(document.frm.companyemail.value);
    var vphoneno=trim(document.frm.phoneno.value);
    var vcaddressline1=trim(document.frm.caddressline1.value);
    var vcaddressline2=trim(document.frm.caddressline2.value);
    var vcaddressline3=trim(document.frm.caddressline3.value);
    var vcountry1=trim(document.frm.country1.value);
    var vstate1=trim(document.frm.state1.value);
    var vcity1=trim(document.frm.city1.value);
    var vpin1=trim(document.frm.pin1.value);


      if(vfname=="")
    {
        alert("Fisrt Name Field is Empty");
        document.frm.fname.focus();
        return false;
    }
    else if(vlname=="")
    {
        alert("Last Name Field is Empty");
        document.frm.lname.focus();
        return false;
    }
    else if(vdatepicker1=="")
    {
        alert("DOB Field is Empty");
        document.frm.datepicker1.focus();
        return false;
    }
    else if(vmobile=="")
    {
        alert("Mobile Number Field is Empty");
        document.frm.mobile.focus();
        return false;
   }
   else if(vaddressline1=="")
   {
        alert("Address Line1 Field is Empty");
        document.frm.addressline1.focus();
        return false;
   }
   else if(vaddressline2=="")
   {
        alert("Address Line2 Field is Empty");
        document.frm.addressline2.focus();
        return false;
   }
   else if(vaddressline3=="")
   {
        alert("Address Line3 Field is Empty");
        document.frm.addressline3.focus();
        return false;
   }
   else if(vcountry=="")
   {
        alert("Country Field is Empty");
        document.frm.country.focus();
        return false;
   }
   else if(vstate=="")
   {
        alert("State Field is Empty");
        document.frm.state.focus();
        return false;
   }
   else if(vcity=="")
   {
        alert("City Field is Empty");
        document.frm.city.focus();
        return false;
   }
   else if(vpin=="")
   {
        alert("Pin Address Field is Empty");
        document.frm.pin.focus();
        return false;
   }
   else if(vcompanyname=="")
   {
        alert("Company Name Field is Empty");
        document.frm.companyname.focus();
        return false;
   }
   else if(vwebsite=="")
   {
        alert("Website Field is Empty");
        document.frm.website.focus();
        return false;
   }
   else if(vcompanyemail=="")
   {
        alert("Email Field is Empty");
        document.frm.companyemail.focus();
        return false;
   }
   else if(vphoneno=="")
   {
        alert("Phone Number Field is Empty");
        document.frm.phoneno.focus();
        return false;
   }
   else if(vcaddressline1=="")
   {
        alert("Address Line 1 Field is Empty");
        document.frm.caddressline1.focus();
        return false;
   }
  else if(vcaddressline2=="")
  {
       alert("Address Line 2 Field is Empty");
       document.frm.caddressline2.focus();
       return false;
  }
  else if(vcaddressline3=="")
  {
       alert("Address Line 3 Field is Empty");
       document.frm.caddressline3.focus();
       return false;
  }
  else if(vcountry1=="")
  {
       alert("Country Field is Empty");
       document.frm.country1.focus();
       return false;
  }
  else if(vstate1=="")
  {
       alert("State Field is Empty");
       document.frm.state1.focus();
       return false;
  }
  else if(vcity1=="")
  {
      alert("City Field is Empty");
      document.frm.city1.focus();
      return false;
  }
  else if(vpin1=="")
  {
      alert("Pin Address Field is Empty");
      document.frm.pin1.focus();
      return false;
  }

}

function trim(s) {
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
</script>
</head>
<body>
  <div id="contact">
    <form id="personalinfo" name="frm" action="home.php" method="post" onSubmit="return validate();">
        <h1>PERSONAL INFORMATION</h1>
       <div style="margin-left:50px">
        <input type="text" name="fname" id="firstname" placeholder="enter your firstname" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="lname" id="lastname" placeholder="enter your last name" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" id="datepicker1" name="datepicker" placeholder="Enter your date of Birth"/></div>
        <div style="margin-left:50px">
        <input type="number" name="mobile" id="mobile" placeholder="enter your mobile number" onkeypress="return isNumberKey(event)"></div>
        <div style="margin-left:50px">
        <input type="text" name="addressline1" id="addressline1" placeholder="enter your addressline 1" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="addressline2" id="addressline2" placeholder="enter your addressline 2" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="addressline3" id="addressline3" placeholder="enter your addressline 3" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="country" id="country" placeholder="enter your country" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="state" id="state" placeholder="enter your state" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="city" id="city" placeholder="enter your city" onkeypress="return onKeyPressBlockNumbers(event);" ></div>
        <div style="margin-left:50px">
        <input type="text" name="pin" id="pin" placeholder="enter your pin address" onkeypress="return isNumberKey(event)"></div>

    <div style="margin-left:500px;margin-top:-550px;"> 
        <div style="margin-left:-122px;margin-top:-400px;"></div>
        <input type="text" name="comapnyname" id="companyname" placeholder="enter your company name" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="text" name="website" id="website" placeholder="enter your company website" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="email" name="companyemail" id="companyemail" placeholder="enter your company email">
        <input type="number" name="phoneno" id="phoneno" placeholder="enter your phone number" onkeypress="return isNumberKey(event)">
        <input type="text" name="caddressline1" id="caddressline1" placeholder="enter your addressline 1" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="text" name="caddressline2" id="caddressline2" placeholder="enter your addressline 2" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="text" name="caddressline3" id="caddressline3" placeholder="enter your addressline 3" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="text" name="country1" id="country1" placeholder="enter your country" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="text" name="state1" id="state1" placeholder="enter your state" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="text" name="city1" id="city1" placeholder="enter your city" onkeypress="return onKeyPressBlockNumbers(event);" >
        <input type="number" name="pin1" id="pin1" placeholder="enter your pin address" onkeypress="return isNumberKey(event)">
        </div>

        <div style="margin-left:-1000px"><input type="submit" id="submit" value="SAVE"/></div>
               </form>
  </div>
 HI <?php echo $_SESSION['username'];?>

</body>
</html>

我真的很困惑我做错了什么,请纠正我 提前谢谢

1 个答案:

答案 0 :(得分:4)

login.php中,表单操作将转到profile.php

<form id="myForm1" action="profile.php" method="post">

profile.php中,您未设置任何$_SESSION个变量。您需要将当前位于login.php的这些行移至profile.php的顶部:

if (isset($_POST['Submit'])) {
    $_SESSION['username'] = $_POST['username'];
}
相关问题