2

現在、Screets Wordpress Sessions Pluginを使用し、カスタム ログイン フォームを使用しています [WP_users データベースと Wordpress の Admin for Users を使用したくないためです。これには私なりの理由があります。]

私のログイン設定は、Wordpress がセッションを削除するという事実を除いて、完全に機能します。私は更新中に危険にさらされるためにコア ファイルをハッキングしたくありません。以下は私のセットアップです:

ログインフォーム:

<form method="post" action="" id="login_form">
<div align="center">
<div >
   User Name : <input name="username" type="text" id="username" value="" maxlength="20" />
</div>
<div style="margin-top:5px" >
   Password :
    &nbsp;&nbsp;
    <input name="password" type="password" id="password" value="" maxlength="20" />
</div>
<div class="buttondiv">
    <input name="Submit" type="submit" id="submit" value="Login" style="margin-left:-10px; height:23px"  /> <span id="msgbox" style="display:none"></span>
</div>
</div>
</form> 

Ajax スクリプト

<script>
$("#login_form").submit(function(event){

    //remove all the class add the messagebox classes and start fading
    $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
    //check the username exists or not from ajax
    $.post("<?php echo get_stylesheet_directory_uri(); ?>%page%.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
      if(data=='yes') //if correct login detail
      {
        $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
        {
          //add message and change the class of the box and start fading
          $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
                  function()
          {
             //redirect to secure page
             document.location='/my-dashboard';
          });
        });
      }
      else
      {
        $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
        {
          //add message and change the class of the box and start fading
          $(this).html('Your login detail sucks...').addClass('messageboxerror').fadeTo(900,1);
        });
          }
       });
       return false;//not to post the  form physically
});
</script>

DB リンク

$username= mysql_escape_string(do something to username);
$pass= mysql_escape_string(do something to pass);

//now validating the username and password
$sql="SELECT username, password FROM %table% WHERE username='".$username."' AND active='1'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result); 

//if username exists
if(mysql_num_rows($result)>0)
{
  //compare the password
  if(strcmp($row['password'],$pass)==0)
  {
    echo "yes";

    //now set the session from here if needed
    $array = array(
    'username' => $row['username']
    );
    $session->set_userdata( $array );
    //$_SESSION['username']=$username;
    //$_SESSION['loggedIn'] = 1;

  }
  else
    echo "no";
}
else
  echo "no"; //Invalid Login

コードはビットを除いてうまく機能します

$array = array(
        'username' => $row['username']
        );
        $session->set_userdata( $array );

これがプラグインでセッションを設定する唯一の方法ですが、「非オブジェクトでメンバー関数 set_userdata() を呼び出します」というエラーが表示されます。現在のセットアップでこれを行う別の方法や、デフォルトの PHP セッションを正しく有効にする方法はありますか? ありがとう。

4

1 に答える 1

1

私はあなたが使用する必要があると思います

$sql="SELECT username, password FROM %table% WHERE username='".$username."' 
  AND active=1"; 

if(is_object($session))  $session->set_userdata( $array );

http://codecanyon.net/item/wordpress-sessions-plugin-with-database/3405722

于 2012-11-19T06:00:08.013 に答える