Shadow_Walker Posted March 4, 2015 Share Posted March 4, 2015 Hello Guys, I have coded a successful log of accounts in localhost but when i uploaded this to webhost. These set of codes dont work anymore. Please help these are the codes. Student_login_handler.php include_once 'Connect.php'; $flag = ""; $learner_id = mysql_real_escape_string(htmlentities($_POST['learner_id'])); $student_password = mysql_real_escape_string(htmlentities($_POST['student_password'])); $student_id = htmlentities($_GET['id'], ENT_QUOTES); $student_id = htmlentities($_GET['id'], ENT_QUOTES); $query = "SELECT student_id,last_login_date FROM student_information WHERE learner_id='$learner_id' and student_password='$student_password'"; $result = mysqli_query($link_id, $query); if(mysqli_error() != null){ die(mysqli_error()); } if($date = mysqli_fetch_array($result)) { $lastdate = $date['last_login_date']; $date2 = date("d-m-Y h:i A",strtotime($lastdate)); $_SESSION['user_id'] = $date['student_id']; $_SESSION["lastlogin"] =$date2; $_SESSION["type"] = "Student"; mysqli_query("UPDATE student_information SET last_login_date=now() where student_id='{$_SESSION['user_id']}'",$link_id); if(mysqli_error() != null){ die(mysqli_error()); } header("location: Student_Home.php?id={$_SESSION['user_id']}"); die(); } else { $flag = "invalid"; header("location:Student_login.php?flag=$flag"); die(); } ?> Student_login.php <form name="form2" method="post" action="Student_login_handler.php" onSubmit="return validate();"> <tr> <td colspan="4"><table width="30%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#666666" bgcolor="#CCCCCC"> <tr align="center" bgcolor="#999999"> <td colspan="2" bgcolor="#99CC33" class="styleblock">Learner Login Here</td> </tr> <tr bgcolor="#E1E1E1" class="stylesmall"> <td width="35%" align="left" class="stylesmall">Learner Id : </td> <td width="65%" align="left"><input name="learner_id" type="text" id="learner_id" method="post"></td> </tr> <tr bgcolor="#E1E1E1" class="stylesmall"> <td align="left" class="stylesmall">Password:</td> <td align="left"><input name="student_password" type="password" id="student_password" method="post"></td> </tr> <tr bgcolor="#E1E1E1"> <td colspan="2" align="center"> <?php if(!empty($_GET['flag']) && $_GET['flag'] == "invalid") { ?> <span class="stylered">Invalid Learner Id or Password</span> <?php }?></td> </tr> <tr bgcolor="#E1E1E1"> <td colspan="2" align="center"> <p><input name="login" class="stylesmall" type="submit" id="login" value="Login"></p> Note: This perfectly function on localhost but not in webhosts. function: the user can log in to its user account problem: different user log in directed to same account Please anyone spare time for me. Quote Link to comment https://forums.phpfreaks.com/topic/295089-logging-in-to-different-user-accounts-but-directed-only-to-same-accoount/ Share on other sites More sharing options...
maxxd Posted March 6, 2015 Share Posted March 6, 2015 Honestly, I can't see how this is working even on your local host. You're using mysql_real_escape_string() with mysqli() functions, which I'm pretty sure won't work. Admittedly, I could be wrong about that, but you really should be using prepared statements and avoiding the issue entirely. You're already halfway there by using mysqli() instead of mysql(), so why not go the extra step and save yourself work in the long run? Also, you're trying to pull array values from $date which isn't defined in the code you posted. You just try to grab a value from it on line 19. In addition, it's a bit misleading to call a variable $date when it includes student id and last login date - this obviously won't stop your script from running, but it will make life harder when you inevitably revisit the code later on. Maybe $student_login_info would be a better name for the array? Finally, do you have error reporting and display turned on, and what are the specs of the two servers? Quote Link to comment https://forums.phpfreaks.com/topic/295089-logging-in-to-different-user-accounts-but-directed-only-to-same-accoount/#findComment-1507777 Share on other sites More sharing options...
mac_gyver Posted March 6, 2015 Share Posted March 6, 2015 Honestly, I can't see how this is working even on your local host. unfortunately, a lot of the xAMP development packages set up default root database credentials in the php.ini that allow mysql_ functions to automatically make a working database connection, thereby hiding bad code that should fail and call your attention to a problem, instead of silently appearing to work, that then won't work on a live server. Quote Link to comment https://forums.phpfreaks.com/topic/295089-logging-in-to-different-user-accounts-but-directed-only-to-same-accoount/#findComment-1507783 Share on other sites More sharing options...
maxxd Posted March 6, 2015 Share Posted March 6, 2015 unfortunately, a lot of the xAMP development packages set up default root database credentials in the php.ini that allow mysql_ functions to automatically make a working database connection, thereby hiding bad code that should fail and call your attention to a problem, instead of silently appearing to work, that then won't work on a live server. Well that doesn't help anybody... Does it override error_reporting(-1), though? Because I'm fairly certain the code above should be throwing some errors - if nothing else than for trying to grab values from the apparently undefined $data array. It's been forever since I built development Ubuntu server and I can't remember if I had to modify the php.ini for error display. Quote Link to comment https://forums.phpfreaks.com/topic/295089-logging-in-to-different-user-accounts-but-directed-only-to-same-accoount/#findComment-1507793 Share on other sites More sharing options...
sowna Posted May 7, 2015 Share Posted May 7, 2015 what error you getting? or how you saying ur function is not working as expected? Quote Link to comment https://forums.phpfreaks.com/topic/295089-logging-in-to-different-user-accounts-but-directed-only-to-same-accoount/#findComment-1511014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.