2016-09-24 4 views
0

データベース接続を開くための接続変数を取得する際に問題があります。フォームで送信されたクラスから接続変数を取得する

<form action="password.php" method="post"> 
      <div class="form-group"> 
       <input type="password" class="form-control" name="current" placeholder="Contraseña Actual..." /> 
      </div> 
      <div class="form-group"> 
       <input type="password" class="form-control" name="new" placeholder="Nueva Contraseña..." /> 
      </div> 
      <div class="form-group"> 
       <input type="password" class="form-control" name="confirm" placeholder="Repetir Nueva Contraseña..." /> 
      </div> 
      </div> 
     <div class="modal-footer"> 
     <input type="hidden" name="q" value="proofQueries"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button> 
     <button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> Cambiar</button> 
     </form> 

HTMLでこの私のコード間、私は、関数を呼び出す方法のモデルを変更することができ、私のクラスのphp

$settings = new Datasettings(); 

require_once('../config.php'); // file of connection of PDO 
$conexion = new Conexion(); 


if(isset($_POST['q'])){ // get the name from html form for go to a function of this class 

    $settings->$_POST['q']($conexion); 
} 

class Datasettings { 

    function __construct(){ 
     session_start(); 
     if(!isset($_SESSION['id'])){ 

      header('location:mystyle.css'); 

     } 
    } 

    function proofQueries($conexion){ 
    } 


... other functions.... 

のコード?どうすればそれを作ることができますか?

+0

$設定 - > $ _ POST ['q']($ conexion); 'いい計画のようには思われません... – Rasclatt

+0

あなたは何をしようとしていますか?何があなたの持っているもので働いていないのですか? – Rasclatt

+0

確定関数を使って$ conexion PDO変数をクラスに送る必要があったので、私はフォームを使って関数を呼び出そうとしました。私は方法を見つけました、今私はaction = ""でフォームを送り、 "isset"でデータを取得します。関数にパラメータを送る別の方法はありますか? –

答えて

0

私はこのコードで想定しています

if(isset($_POST['q'])){ // get the name from html form for go to a function of this class 
    $settings->$_POST['q']($conexion); 
} 

と価値proofQueriesqと呼ばれる隠しフォームフィールドを提出、あなたは$settings->proofQueries($conexion)を呼び出そうとしています。これは非常に悪い考えです。

クライアント側から直接アクセスするコードは、HUGEという脆弱性があります。

まず関数クライアント側を指定し、PHP(つまりサーバー側)で実行するのは、奇妙なアプローチのようです。 PHPで$settings->proofQueries($conexion)を明示的に実行する代わりに、qの値を指定するのはなぜですか?

あなたは何とかはこのような何か、クライアント側呼び出される関数を指定必要がある場合:

if(isset($_POST['q'])){ // get member function from submitted form 
    $f = $_POST['q']; 
    if ($f=='proofQueries') { 
    $settings->proofQueries($conexion); 
    } 
    else { 
    die("Nope"); 
    } 
} 

それとも、複数の可能な機能を持っている場合は、明示的に絶対に100を作るためにホワイトリストでそれらをフィルタリングしますあなたが決めるONLY関数名を呼び出すことができるようわから%:

if(isset($_POST['q'])){ // get member function from submitted form 
    $f = $_POST['q']; 
    $allowedFunctions = array('proofQueries','doSomething','otherFunction'); 
    if (in_array($f,$allowedFunctions)) { 
    $settings->$f($conexion); 
    } 
    else { 
    die("Nope"); 
    } 
} 

しかし、再び、それはalltogether奇妙なアプローチのように思えます。クライアント側では、サーバー側の実装の詳細を指定しないでください。

関連する問題