2011-05-07 140 views
0

我試着在我的網站上做到這一點,我有這個代碼在我的Joomla instalations中工作,但它不能在另一個joomla instalation上工作。在不能正常工作的情況下,腳本會搜索數據庫並找到用戶憑據,但當它轉到mywebsite.com時,它不會登錄用戶。用戶密碼未加密,這是我僅用於此目的的另一個字段。有人能幫我找出有什麼問題嗎?使用捲曲在Joomla外登錄

<?php 
mysql_connect("localhost", "sqluser", "sqlpass") or die(mysql_error()); 
mysql_select_db("sqldb") or die(mysql_error()); 
$uname = $_POST['username']; 
$upswd = $_POST['password']; 
$result_user = mysql_query("SELECT username FROM jos_users where username = '$uname'") or die(mysql_error()); 
$rows_user = mysql_num_rows($result_user); 
$result_pass = mysql_query("SELECT vm_pass_lojat FROM jos_vm_user_info where vm_pass_lojat = '$upswd'") or die(mysql_error()); 
$rows_pass = mysql_num_rows($result_pass); 
if($rows_user > 0){ 
    if($rows_pass > 0){ 
     $url = "http://www.mywebsite.com/online/index.php"; 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
     curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); 
     curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('./cookie.txt')); 
     curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('./cookie.txt')); 
     curl_setopt($ch, CURLOPT_HEADER, TRUE); 
     $ret = curl_exec($ch); 
     if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)){ 
      preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof); 
      } 
     // POST fields 
     $postfields = array(); 
     $postfields['username'] = urlencode($uname); 
     $postfields['passwd'] = urlencode($upswd); 
     $postfields['option'] = 'com_user'; 
     $postfields['task'] = 'login'; 
     $postfields[$spoof[1]] = '1'; 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 
     $ret = curl_exec($ch); 
     // Get logged in cookie and pass it to the browser 
     preg_match('/^Set-Cookie: (.*?);/m', $ret, $m); 
     $cookie = explode('=', $m[1]); 
     setcookie($cookie[0], $cookie[1]); 
     header("location: http://www.mywebsite.com/online/index.php"); 
     } 
    else 
     { 
     echo "WRONG PASSWORD"; 
    } 
    } 
else 
    { 
    echo "NO USER FOUND"; 
} 
?> 
+0

你忘記縮進你的代碼了嗎? – 2011-05-07 09:39:40

+0

現在它縮進了,但仍然不起作用,它會建立與數據庫的連接,並找到我希望它找到並重定向到我想要的網站的數據,但不會將其登錄到我的網站。 – 2011-05-09 14:38:47

+0

代碼後面的代碼是什麼運行? – 2011-06-06 07:29:38

回答

0

後端的身份驗證插件可能未處於活動狀態。