Hello, I'm trying to create a selector menu in an iframe similar to the way com_media is used using an existing joomla component that doesn't seem to be designed for the task. I thought I would curl the page and change the links to point to a javascript function in the parent window before displaying. That way I don't modify any of the components original source code. However I'm having trouble logging in to the joomla site using curl. I tried the php code for joomla1.5 which I found @ http://stackoverflow.com/questions/2212557/curl-login-by-script-to-a-joomla-website#answer-4532020 . I changed the sitename username and password, and it doesn't seem to work on joomla 2.5(I haven't tried it using joomla 1.5 but that won't really help me today). I made some changes and tried using the following code which leaves me with an empty looking response, on my second curl(first one works fine). Does anyone know why this isn't working?
<?php $uname = $_POST['username']; $upswd = $_POST['password']; $url = "http://joomla.website.com/administrator/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); // Get and set POST fields $DOM = new DOMDocument; $DOM->loadHTML($ret); $items = $DOM->getElementsByTagName('input'); $postfields = array(); foreach ($items as $item){ if (!(strtolower($item->getAttribute('type'))=="submit")){ $postfields[$item->getAttribute('name')]=$item->getAttribute('value'); } } $postfields['username'] = urlencode($uname); $postfields['passwd'] = urlencode($upswd); $postfields['lang'] = ''; curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $ret = curl_exec($ch); // show the postfields and the results ?><pre><? print_r($postfields); echo htmlentities(sizeof($ret))."\n"; ?></pre> If there's a better way to do this I'm all ears, however I'd like to get this to work too.
_______________________________________________ New York PHP SIG: Joomla! Mailing List http://lists.nyphp.org/mailman/listinfo/joomla NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.php