priya117 Posted June 26, 2013 Share Posted June 26, 2013 Hello friends , I am using PHP 5.4.16 on my linux server and geeting this error in the url echo $_SERVER['PHP_SELF']; ?> when i cleck submit button on my login page , if replace this form action with any required php page say login sucess next page then my java script wont work , Can any one please help me to resolve this issue so that i can run my java script on the same php page , Is there any internal changes we have to do this ? <form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post"> <tr><td colspan="2" align="center"> <input class="text" type="submit" name="submitBtn" value="Login" /> </td></tr> if (isset($_POST['submitBtn'])){ Thanks in advance Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 Very difficult to help when all we are getting is a couple pieces of some supposed code. How about showing us the full lines involved? Not the whole script, but the parts you are mentioning. Quote Link to comment Share on other sites More sharing options...
priya117 Posted June 26, 2013 Author Share Posted June 26, 2013 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform"> <table width="100%"> <tr><td>Username:</td><td> <input class="text" name="username" type="text" /></td></tr> <tr><td>Password:</td><td> <input class="text" name="password" type="password" /></td></tr> <tr><td colspan="2" align="center"> <input name="submit" type="submit" value="Submit" /> </td></tr> </table> </form> if (isset($_POST['submit'])){ // Get user input $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // Try to login the user $error = loginUser($username,$password);} function loginUser($user,$pass){ $errorText = ''; $validUser = false; // Check user existance $pfile = fopen("userpwd.txt","r"); rewind($pfile); while (!feof($pfile)) { $line = fgets($pfile); $tmp = explode(':', $line); if ($tmp[0] == $user) { // User exists, check password if (trim($tmp[2]) == trim(md5($pass))){ $validUser= true; $_SESSION['userName'] = $user; } break; } } fclose($pfile); if ($validUser != true) $errorText = "Invalid username or password!"; if ($validUser == true) $_SESSION['validUser'] = true; else $_SESSION['validUser'] = false; return $errorText; } Can you please explain why my java scrpit is not working for this above code and also i get error in the url as %3C?php echo $_SERVER['PHP_SELF']; if i remove this and redirect to some other php page it ll work but java scrpit does not work , is there any thing to change to run the above in linux , this code works for windows server i m facing this in linux and i am using PHP5 version Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 26, 2013 Share Posted June 26, 2013 for some reason instead of parsing the php it's convert the < to %3C Need to see what's at the top of the page. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform"> <table width="100%"> <tr><td>Username:</td><td> <input class="text" name="username" type="text" /></td></tr> <tr><td>Password:</td><td> <input class="text" name="password" type="password" /></td></tr> <tr><td colspan="2" align="center"> <input name="submit" type="submit" value="Submit" /> </td></tr> </table> </form> if (isset($_POST['submit'])){ // Get user input $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // Try to login the user $error = loginUser($username,$password);} function loginUser($user,$pass){ $errorText = ''; $validUser = false; // Check user existance $pfile = fopen("userpwd.txt","r"); rewind($pfile); while (!feof($pfile)) { $line = fgets($pfile); $tmp = explode(':', $line); if ($tmp[0] == $user) { // User exists, check password if (trim($tmp[2]) == trim(md5($pass))){ $validUser= true; $_SESSION['userName'] = $user; } break; } } fclose($pfile); if ($validUser != true) $errorText = "Invalid username or password!"; if ($validUser == true) $_SESSION['validUser'] = true; else $_SESSION['validUser'] = false; return $errorText; } Can you please explain why my java scrpit is not working for this above code and also i get error in the url as %3C?php echo $_SERVER['PHP_SELF']; if i remove this and redirect to some other php page it ll work but java scrpit does not work , is there any thing to change to run the above in linux , this code works for windows server i m facing this in linux and i am using PHP5 version Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 What is the name of this file? Also - you are wondering about your JS, yet you aren't showing us any JS code. Where does the JS code come into play here? Quote Link to comment Share on other sites More sharing options...
priya117 Posted June 26, 2013 Author Share Posted June 26, 2013 (edited) the name of this file is login.php, and the js is coming from other page(common.php) where it calls the function loginUser <?phprequire_once('common.php'); $error = '0'; if (isset($_POST['submitBtn'])){ // Get user input $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // Try to login the user $error = loginUser($username,$password);}?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"><html><head> <title>NM Application Build</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <!-- <TABLE BORDER CELLSPACING=2 CELLPADDING=7 width="140" height="110" align="left"><TR> <TD VALIGN="TOP" BGCOLOR="white"><img src="images/landg-logo.gif" width="84" height="71" align="center"/> </TD></TR></TABLE> --> <img src="images/title-top-bg.png" align="center"/><br/><br/><br/><br/><br/></head> <body> <marquee scrollamount="4" behavior="alternate" >Welcome to NM Auto Build! </marquee> <br/><br/> <div id="main"><?php if ($error != '') {?> <div class="caption">NM Build Login</div> <div id="icon"> </div> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="loginform"> <table width="100%"> <tr><td>Username:</td><td> <input class="text" name="username" type="text" /></td></tr> <tr><td>Password:</td><td> <input class="text" name="password" type="password" /></td></tr> <tr><td colspan="2" align="center"> <input class="text" type="submit" name="submitBtn" value="Login" /> </td></tr> </table> </form> <a class="button" href="register.php" onclick="this.blur();"><span>Register</span></a> <a class="button" href="forgotpwd.php" onclick="this.blur();"><span>Forgot Password?</span></a> <?php} if (isset($_POST['submitBtn'])){ ?> <div class="caption">Login result:</div> <div id="icon2"> </div> <div id="result"> <table width="100%"><tr><td><br/> <div id="source">MTCM v 1.0</div> </div></body> Edited June 26, 2013 by priya117 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 Am I hearing that you want to call a JS function from PHP? Quote Link to comment Share on other sites More sharing options...
priya117 Posted June 27, 2013 Author Share Posted June 27, 2013 yes on click of submit Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 27, 2013 Share Posted June 27, 2013 Can we see that code? I'm still confused since you seem to be saying now that the js is being called from an html submit and NOT PHP. 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.