Jump to content

Recommended Posts

:confused: 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

 

Link to comment
https://forums.phpfreaks.com/topic/279590-php-error-3cphp-echo-_serverphp_self/
Share on other sites

 <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  :confused: 

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  :confused: 

the name of this file is login.php, and the js is coming from other page(common.php) where it calls the function loginUser 

 

<?php
require_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 by priya117
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.