dongzhao5834 2016-02-18 12:17
浏览 60

提交表单(PHP):提交我的PHP代码后似乎没有执行

I have an issue with my php form. I have an application that manages users in a LDAP server so I want to give the possibility to users to change their password anytime they want to using a form.

In the form we need tree informations (old password, newwpassword and the uid of the concerned ldap entry). We extract the uid from the displayName which can be a complete name: we consider that the first word is always the uid (just to notice it but that's not much important here).

So i have the form with this following code:

<?php
  // echo '<pre>';  
// print_r($_POST);
  // echo '</pre>';

  function str_to_noaccent($str) { 
    $url = $str; 
    $url = preg_replace('#Ç#', 'C', $url); 
    $url = preg_replace('#ç#', 'c', $url); 
    $url = preg_replace('#è|é|ê|ë#', 'e', $url);
    $url = preg_replace('#È|É|Ê|Ë#', 'E', $url);
    $url = preg_replace('#à|á|â|ã|ä|å#', 'a', $url);
    $url = preg_replace('#@|À|Á|Â|Ã|Ä|Å#', 'A', $url);
    $url = preg_replace('#ì|í|î|ï#', 'i', $url);
    $url = preg_replace('#Ì|Í|Î|Ï#', 'I', $url);
    $url = preg_replace('#ð|ò|ó|ô|õ|ö#', 'o', $url);
    $url = preg_replace('#Ò|Ó|Ô|Õ|Ö#', 'O', $url);
    $url = preg_replace('#ù|ú|û|ü#', 'u', $url);
    $url = preg_replace('#Ù|Ú|Û|Ü#', 'U', $url);
    $url = preg_replace('#ý|ÿ#', 'y', $url);
    $url = preg_replace('#Ý#', 'Y', $url);
    return ($url);
  }

  if(isset($_POST['soumission']))
  {
     if(isset($_POST['oldpassword']) && isset($_POST['newpassword']) && isset($_POST['displayName']))
     {
     $oldpasswd = $_POST['oldpassword'];
         $newpassd = $_POST['newpassword'];
         $arr = explode('',$_POST['displayName']);
     $user_uid = str_to_noaccent(strtolower($arr[0]));

         $cmd = exec('script.sh '.$oldpasswd.' '.$newpassd.' '.$user_uid);
     if($cmd)
     {
       echo '<script language="text/javascript">';
       echo 'alert("Mot de passe changé avec succès!")';
       echo '</script>';
     }
     else
     {
       echo '<script language="text/javascript">';
       echo 'alert("Impossible de changer de mot de passe!")';
       echo '</script>';
     }
    }
   }
?>

<form class="section" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
    <h2>Mot de passe</h2>
    <input type="password" name="oldpassword" placeholder="Ancien mot de passe" autocomplete="off" autocapitalize="off" autocorrect="off" />
    <input type="password" id="pass2" data-typetoggle="#personal-show" name="newpassword" placeholder="Nouveau mot de passe" autocomplete="off" autocapitalize="off" autocorrect="off" />
    <input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label>
    <input type="hidden" id="displayName" name="displayName"
    value="<?php p($_['displayName']) ?>"
    autocomplete="on" autocapitalize="off" autocorrect="off" readonly />
    <input type="submit" name="soumission" value="Changer le mot de passe"/>
   <div class="strengthify-wrapper"></div>
</form>
<?php
?>

The content of the script.sh is as follows:

#! /bin/bash
/usr/bin/ldappasswd -h @IP_ldap_server -p 389 -x -D 'cn=admin,dc=xxxxx,dc=xxxxx,dc=xx' -w xxxxxx -a $1 -s $2 uid=$3,ou=xxxx,dc=xxxx,dc=xxxx,dc=xx

Everything like script.sh, str_to_noaccent, etc. have been tested individually and works perfectly. Even the print_r($_POST); shows that form values are well get.

But it seems that the php code is not executed (from the if(isset($_POST['soumission'])) to the end of the first php block). It's been days but I still can figure out why. Can sombebody here help to find what's wrong?

Thank you all very much in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试