2013-03-15 3 views
-1

Я создал страницу входа здесь, это код, я не использую какую-либо базу данных, и я должен нести электронное письмо зарегистрированного пользователя до тех пор, пока он не выйдет из системы, вот моя страница входа (login.php). В форме, которую я назвал веб-службой с некоторыми ключами, я преобразовал ее в 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> 

я действительно смущен от того, что я делаю неправильно, пожалуйста, поправьте me заблаговременно

+0

Вы звоните 'session_start()' на всех страницах? – Mooseman

+0

pipm.php находится в http://pastebin.com/DnM3zcCd, так как у меня меньше 10 репутации, я не могу вставить более двух ссылок, поэтому вот код для pipm.php.Thank вы – user1605946

+0

да, сэр, я звоню session_start on все страницы – user1605946

ответ

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']; 
} 
+0

Спасибо, SeanWM, работает как шарм, у меня есть один вопрос, почему я не могу поставить эту нишу кода в login.php? Почему он находится в profile.php? – user1605946

+0

Спасибо Mooseman, Pitchinnate, inquam – user1605946

+0

ok, я получил ответ на вопрос, который я задал, когда действие формы происходит в profile.php, там написано. – user1605946

Смежные вопросы