简体   繁体   English

页面之间没有会话

[英]session not carrying between the pages

i have created a login page here is the code ,i am not using any database and i am supposed to carry the email of the logged in user until it loggs out ,here is my login page(login.php) . 我已经创建了一个登录页面,这里是代码,我没有使用任何数据库,并且应该携带登录用户的电子邮件,直到注销为止,这是我的登录页面(login.php)。 In the form action i have called a web service with some keys ,i have convereted it into json format and then on sending to server i get a response in json format which is decoded and after checking some condition(all these are happening in profile.php) they are redirected to another page based on the response of the condition check the page to which it is redirected is (pipm.php). 在表单操作中,我已调用带有某些键的Web服务,我将其转换为json格式,然后在发送到服务器时,得到json格式的响应,该响应被解码并检查了某些条件后(所有这些都在配置文件中发生。 php)根据条件的响应将它们重定向到另一个页面,检查该页面重定向到的页面是(pipm.php)。

login.php is 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 is 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 is 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>

i am really confused on what i am doing wrong,please correct me thanks in advance 我对自己做错的事很困惑,请先纠正我,谢谢

In login.php the form action is going to profile.php as such: login.php ,表单操作将这样转到profile.php

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

In profile.php you're not setting any $_SESSION variables. profile.php您没有设置任何$_SESSION变量。 You need to move these lines that are currently in login.php to the top of profile.php : 您需要将当前在login.php中的这些行移动到profile.php的顶部:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM