使用外部表单登录到Joomla 1.5(不在joomla文件夹中,但在同一台服务器上) [英] Logging In To Joomla 1.5 Using External Form (not within joomla folder, but on same server)

查看:126
本文介绍了使用外部表单登录到Joomla 1.5(不在joomla文件夹中,但在同一台服务器上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个Joomla 1.5安装以及另一个网站。它们都驻留在同一个Web服务器上。但是,它们位于wwwroot目录中的不同文件夹中。我想在非joomla网站上放置一个登录表单,该表单会将用户登录到Joomla。我已经尝试将Joomla登录表单代码复制并粘贴到非joomla网站的页面上,并且一切正常,直到秘密表单值不正确。

编辑:
这里是代码 -



联系表格:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title>无标题文档< / title>
< / head>

< body>
< form id =loginname =loginmethod =postaction =login.php>
< label>
< input name =usernametype =textid =usernamevalue =username/>
< / label>
< label>
< input name =passwordtype =passwordid =passwordvalue =password/>
< / label>
< / p>
< p>
< label>
< input type =submitname =submitid =submitvalue =Submit/>
< / label>
< / p>
< / form>
< / body>
< / html>

登录脚本:

 <?php 
$ uname = $ _POST ['username'];
$ upswd = $ _POST ['password'];
$ url =http://www.mywebsite.com/joomla_site/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_COOKIEJAR,'./cookie.txt');
curl_setopt($ ch,CURLOPT_COOKIEFILE,'./cookie.txt');
curl_setopt($ ch,CURLOPT_HEADER,FALSE);
$ ret = curl_exec($ ch);
如果(!的preg_match( '/名称= ([A-ZA-Z0-9] {32})/',$ RET,$欺骗)){
的preg_match(/名称= '([a-zA-z0-9] {32})'/,$ ret,$ spoof);
}

// POST字段
$ postfields = array();
$ postfields ['username'] = urlencode($ uname);
$ postfields ['passwd'] = urlencode($ upswd);
$ postfields ['lang'] ='';
$ postfields ['option'] ='com_login';
$ postfields ['task'] ='login';
$ postfields [$ spoof [1]] ='1';
curl_setopt($ ch,CURLOPT_POST,1);
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ postfields);
$ ret = curl_exec($ ch);
?>


解决方案

好的,为了在这里工作,需要完成 -


  1. 创建新会话并获取关联的令牌

  2. 传递用户名,密码和令牌来创建登录会话

  3. 获取登录会话的新cookie值
  4. 将cookie传输到浏览器
  5. >

以下是完成所有这些所需的代码:

 <?php 
$ uname = $ _POST ['username'];
$ upswd = $ _POST ['password'];
$ url =http:// joomla website.com;

$ 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字段
$ 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);

//获取cookie并将其传递给浏览器
preg_match('/ ^ Set-Cookie:(。*?); / m',$ ret,$ m);
$ cookie = explode('=',$ m [1]);
setcookie($ cookie [0],$ cookie [1]);
?>

只要脚本中使用的URL具有登录表单,就可以在任何Joomla网站上使用这一页。一旦你运行这个脚本,你应该能够访问该网站并登录。


I currently have a Joomla 1.5 installation, as well as another website. They both reside on the same web server. They are in different folders within the wwwroot directory, however. I would like to place a login form within the non-joomla website, which will log the user in to Joomla. I have already tried copying and pasting the Joomla login form code into a page on the non-joomla site, and everything works fine up until the secret form value is not correct. Any help is greatly appreciated.

EDIT: Here is the code-

Contact form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="login" name="login" method="post" action="login.php">
  <label>
  <input name="username" type="text" id="username" value="username" />
  </label>
    <label>
    <input name="password" type="password" id="password" value="password" />
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>

Login Script:

<?php
$uname = $_POST['username'];
$upswd = $_POST['password'];
$url = "http://www.mywebsite.com/joomla_site/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_COOKIEJAR, './cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, FALSE );
$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['lang'] = '';
$postfields['option'] = 'com_login';
$postfields['task'] = 'login';
$postfields[$spoof[1]] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
?>

解决方案

Ok, in order for this to work here is what needs to be done -

  1. Create a new session and get the associated token
  2. Pass the username, password, and token to create a logged in session
  3. Get the new cookie values for logged in session
  4. Transfer cookie to the browser

Here is the code needed to accomplish all of this:

<?php
$uname = $_POST['username'];
$upswd = $_POST['password'];
$url = "http://joomla website.com";

$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]);
?>

This should work on any Joomla website as long as the URL used in the script has a login form on the page. Once you run this script you should then be able to access the website and be logged in.

这篇关于使用外部表单登录到Joomla 1.5(不在joomla文件夹中,但在同一台服务器上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆