I-AM-OBODO Posted March 18, 2013 Share Posted March 18, 2013 Hi all, I am going bald on this one. I wonder what could be wrong. I could login to my local server but cant login in a live server! thanks all <?php if(isset($_POST['login'])){ $tbl_name="reg_users"; // Define $myusername and $mypassword $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); if($username == ''){ echo "<font color='red' size='-2'><b>Pls Enter User ID</b></font>"; } if($password == ''){ echo "<font color='red' size='-2'><b>Pls Enter Password</b></font>"; }else{ $crypt_pass = md5($password); //check for existance of username and password $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$crypt_pass'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register username and password and redirect to login page" $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location: ../folder/filename.php"); exit(); } else { //if no match found, echo out error message echo "<font color='red' size='2'><b>Invalid User ID or Password</b></font><br>"; } } } ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 Its not redirecting to the intended location Quote Link to comment Share on other sites More sharing options...
Yohanne Posted March 18, 2013 Share Posted March 18, 2013 if you are using require tag, change it into include. try. Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 if you are using require tag, change it into include. try. thanks. tried it but still same problem though Quote Link to comment Share on other sites More sharing options...
Yohanne Posted March 18, 2013 Share Posted March 18, 2013 what probably error say? or check out quote header('Location:page.php'); Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 what probably error say? or check out quote header('Location:page.php'); no error, just wont redirect to intended location. works fine on my wamp Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 (edited) i decided to try and create a different file for the login page instead using both code and form in same page and it worked! why wont <?=$_SERVER['PHP_SELF']?> work in my live server? Edited March 18, 2013 by Mr-Chidi Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 18, 2013 Share Posted March 18, 2013 It depends on what you mean by "doesn't work", but it sounds like your live server doesn't have short tags enabled. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted March 18, 2013 Share Posted March 18, 2013 (edited) $_SERVER['PHP_SELF'] should never be used as a forms action, as it can rather easily be spoofed. Instead if you want the form to submit to itself, use action='' Edited March 18, 2013 by AyKay47 Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 It depends on what you mean by "doesn't work", but it sounds like your live server doesn't have short tags enabled. doesnt work means i could not redirect to my intended page. and how do i check if my live server doesn't have short tags enable and can i enable(nope i guess) what beats me is that it works on my wamp and i could reach other pages in my target directory Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 $_SERVER['PHP_SELF'] should never be used as a forms action, as it can rather easily be spoofed. Instead if you want the form to submit to itself, use action='' thanks and noted Quote Link to comment Share on other sites More sharing options...
ignace Posted March 18, 2013 Share Posted March 18, 2013 what beats me is that it works on my wamp and i could reach other pages in my target directoryWamp has short tags enabled, your live server probably doesn't. You can easily check this. If short tags are disabled you'll see, as plaintext:action="<?= $_SERVER['PHP_SELF'] ?>"In your browser view source. Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 18, 2013 Author Share Posted March 18, 2013 I do not think the problem is as a result of short tags cos i just tried it with aykay47 method (action="") and still the same behavior. What on earth could be wrong!!!! Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 19, 2013 Share Posted March 19, 2013 You're not giving us nearly enough information to help you. Where exactly is the problem? Quote Link to comment Share on other sites More sharing options...
akphidelt2007 Posted March 19, 2013 Share Posted March 19, 2013 Is the live server's directory set up the same as your local server? ../folder might not be the same on the live server. Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 19, 2013 Author Share Posted March 19, 2013 You're not giving us nearly enough information to help you. Where exactly is the problem? the problem is that when the username and password is entered, it suppose to redirect to an index but it is not redirecting, but again i could access other pages inside the target folder (which means the session have been set. because it displays the welcome username) Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 19, 2013 Share Posted March 19, 2013 have you tried just putting header() up without any IFs and see if that even redirects? Just guessing here Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted March 19, 2013 Share Posted March 19, 2013 (edited) What debugging steps have you taken? Make sure error_reporting is set to E_ALL or -1 and display_errors is set to ON or 1 It may help to post the form Edited March 19, 2013 by AyKay47 Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted March 19, 2013 Author Share Posted March 19, 2013 What debugging steps have you taken? Make sure error_reporting is set to E_ALL or -1 and display_errors is set to ON or 1 It may help to post the form I do not have control over my live server (host) but from my localhost, all is working fine! Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted March 19, 2013 Share Posted March 19, 2013 (edited) You can use this at the top of your scripts: error_reporting(E_ALL); ini_set('display_errors', 1); Edited March 19, 2013 by PaulRyan Quote Link to comment 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.