PHP - Php, Curl And Loggin On To Joomla
Hi
I am trying to knock up a script to create a userid and log someone into a Joomla based site. The script is running on the same server as the site (and is legitimate, not nefarious). I can create an ID OK, and I can retrieve the login page, scrape the details (including the token) and submit the form. When I do this the user is logged in according to the Joomla sessions table, but it has also created a 2nd guest session there. Navigating to the Joomla site (either manually or doing a header redirect) just takes you to the site as though you are not logged in. Code as it stands (and code to deal with being passed user ids and passwords will change to be at least vaguely secure, just trying to get things to work now) Code: [Select] <?php session_start(); session_regenerate_id(); require("configuration.php"); $ConfigDetails = new JConfig(); $dbms = $ConfigDetails->dbtype; $dbhost = $ConfigDetails->host; $dbname = $ConfigDetails->db; $dbuser = $ConfigDetails->user; $dbpasswd = $ConfigDetails->password; $salt = 'somesalt'; $url = "http://localhost/joomla/index.php"; $IncomingUid = $_REQUEST['uid']; $IncomingName = $_REQUEST['name']; $IncomingPassword = $_REQUEST['pwd']; $IncomingEmail = $_REQUEST['email']; // Make the database connection. $SurveyConn = mysql_connect($dbhost,$dbuser,$dbpasswd); mysql_select_db($dbname,$SurveyConn) or die(mysql_error()); $sql = "SELECT * FROM ".$ConfigDetails->dbprefix."users WHERE username = '".mysql_real_escape_string($IncomingUid)."'"; $rs = mysql_query($sql) or die(mysql_error()); if ($row = mysql_fetch_assoc($rs)) { if ($IncomingPassword == $row['password']) { } } else { $PasswordEncrypted = md5($IncomingPassword.$salt).':'.$salt; $sqli = "INSERT INTO ".$ConfigDetails->dbprefix."users (id, name, username, email, password, usertype, block, sendEmail, registerDate, lastvisitDate, activation, params) VALUES(NULL, '".mysql_real_escape_string($IncomingName)."','".mysql_real_escape_string($IncomingUid)."','".mysql_real_escape_string($IncomingEmail)."','".mysql_real_escape_string($PasswordEncrypted)."','deprecated',0,1,NOW(), NOW(), '', '')"; $rs = mysql_query($sqli) or die(mysql_error()." $sqli"); $sqli = "INSERT INTO ".$ConfigDetails->dbprefix."user_usergroup_map (user_id, group_id) VALUES(".mysql_insert_id().", 8)"; $rs = mysql_query($sqli) or die(mysql_error()." $sqli"); } $agent = "'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6'"; $c1 = curl_init(); curl_setopt($c1, CURLOPT_URL, $url ); curl_setopt($c1, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt($c1, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt($c1, CURLOPT_VERBOSE, 1); curl_setopt($c1, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($c1, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($c1, CURLOPT_USERAGENT, $agent ); curl_setopt($c1, CURLOPT_HEADER, TRUE ); curl_setopt($c1, CURLOPT_REFERER, $url1); curl_setopt($c1, CURLOPT_POST, 1); $html = curl_exec($c1); $dom = new DOMDocument(); $FormFieldsArray = array(); if (@$dom->loadHTML($html)) { // yep, not necessarily valid-html... $xpath = new DOMXpath($dom); $nodeListInputs = $xpath->query('//input'); if ($nodeListInputs->length > 0) { $FormFieldsArray = array(); for ($i=0 ; $i<$nodeListInputs->length ; $i++) { $nodeInput = $nodeListInputs->item($i); $name = $nodeInput->getAttribute('name'); $value = $nodeInput->getAttribute('value'); $FormFieldsArray[$name] = $value; } } } else { // too bad... } if (count($FormFieldsArray) > 0) { $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_VERBOSE, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_USERAGENT, $agent ); curl_setopt($ch, CURLOPT_HEADER, TRUE ); curl_setopt($ch, CURLOPT_REFERER, $url1); // POST fields $postfields = array(); foreach($FormFieldsArray AS $FormFieldName=>$FormFieldValue) { switch ($FormFieldName) { case 'username' : $postfields['username'] = urlencode($IncomingUid); break; case 'passwd' : $postfields['passwd'] = urlencode($IncomingPassword); break; case 'password' : $postfields['password'] = urlencode($IncomingPassword); break; default : $postfields[$FormFieldName] = $FormFieldValue; break; } } 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: ".$url); } //echo $ret; ?> Any ideas? All the best Keith Similar TutorialsHi all. I'm really having an awful time. Pls what could be the problem with this cos i can login into my local server but cant login when i go live.
thanks
<?php if(isset($_POST['login'])){ $username=$_POST['username']; $password=$_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $pass = md5($password); $stmt = $pdo->prepare("SELECT * FROM confirm WHERE username=:username AND password=:password"); $stmt->execute(array( ':username' =>$username, ':password' => $pass )); if ($stmt->rowCount() ==1){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location: ./account/"); exit(); } else { echo 'Invalid Username or Password'; } } ?> Im having issues with logging out of a my website. I have successfully managed to log in. I am using sessions to do it and have been using session_unregister, which I believe is not depreciated. I have tried using unset but I am now getting the error
Parse error: syntax error, unexpected '"authenticatedUser"' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\ShreddedNutrition\HTML\Logout.php on line 8this is my log out code <?php session_start(); $appUsername = $_SESSION["authenticatedUser"]; $_SESSION["message"] = "You Have Logged out"; unset("authenticatedUser"); // Relocate back to the login page header("Location: Login.php"); //session_destroy(); ?>and this is to log in <?php include 'db.inc'; session_start(); $UserEmail =$_POST["EmailAddress"]; $UserPassword =$_POST["Password"]; $query = "SELECT * FROM members WHERE EmailAddress = '$UserEmail' AND password = '$UserPassword' "; $connection = mysql_connect($hostname, $username, $password) or die ("Unable to connect!"); mysql_select_db($databaseName) or die ("Unable to select database!"); $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { $_SESSION["authenticatedUser"] = $UserEmail; // Relocate to the logged-in page header("Location: Index.php"); } else { $_SESSION["message"] = "Could not connect log in as $UserEmail " ; header("Location: Login.php"); } mysql_free_result($result); mysql_close($connection); ?> good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. Hello all,
I have a question. The server I am currently working on is on PHP 5.2 and Joomla 1.5.26. I'd like to migrate or slowly move over to 3.0 on the same server however 3.0 requires at least 5.3 (would go to 5.4). In my cpanel, it tells me "PHP 5.4+ Incompatible Applications Installed". Is it not possible to run Joomla 1.5 on PHP 5.4, or are there certain components/modules that do not work with it?
The two major third party components I have installed are Community Builder and Jumi.
I just don't want my site to explode if I click the button.
Thanks,
Rob
Edited by Spikes, 10 November 2014 - 10:21 PM. I'm trying to implement a custom css style for each of the K2 templates.
I wrote a com_K2 override.
I add this string to a K2 template php files
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/html/com_k2/templates/default/k2c.css" type="text/css" />but it adds itself in the body of the page. Is there a way to put this string into <head> tag? I'm not savvy in PHP, so any advice would be appreciated Hello, Hi ,
My site gives a blank page when i click on an article due to insufficient memory. I tried making changes to the php.ini file but the changes are not getting reflected.
Please advice if a server restart is needed for this, how do i go about it?
Thanks in advance
A joomla module have the following code which displays the date of an article, and to a seperate line the linked title of that article.
Please help me on how to change that code so that the date and the title of the article to be presented in the same line?
<div class="smartlatest-title"> <?php if($params->get('show_date',1)) echo '<div class="smartlatest-date">'.strftime($params->get('date_format','%d-%m-%Y'), strtotime($item->publish_up)).'</div>'; ?> <?php if($params->get('link_title',1)) { ?><a href="<?php echo $item->link; ?>" class="smartlatest-title-link"><?php } ?> <?php echo $item->title; ?> <?php if($params->get('link_title',1)) { ?></a><?php } ?> </div> Hi there,
I have decided using the Joomla API however, the documentation was for 1.5 and 2.5 system only but i'm using 3.0. I have a number of files that look like this:
"14-05-14 JoePharnel.pdf"
and
"13-05-12 HarryCollins.pdf"
Basically I want to create a PHP code that when someone ftp uploads those files to the upload folder that it will 1) Create a directory if it doesn't exist using there name 2) Move the files to the correct directory (E.g. JoePharnel to the JoePharnel Directory ignoring the number at the beginning)
My new code creates the folder but won't move the file in the upload into that new folder, code is below:
<?php define( '_JEXEC', 1); define('JPATH', dirname(__FILE__) ); if (!defined('DS')){ define( 'DS', DIRECTORY_SEPARATOR ); $parts = explode( DS, JPATH ); $script_root = implode( DS, $parts ) ; // check path $x = array_search ( 'administrator', $parts ); if (!$x) exit; $path = ''; for ($i=0; $i < $x; $i++){ $path = $path.$parts[$i].DS; } // remove last DS $path = substr($path, 0, -1); if (!defined('JPATH_BASE')){ define('JPATH_BASE', $path ); } if (!defined('JPATH_SITE')){ define('JPATH_SITE', $path ); } /* Required Files */ require_once ( JPATH_SITE . DS . 'includes' . DS . 'defines.php' ); require_once ( JPATH_SITE . DS . 'includes' . DS . 'framework.php' ); require_once ( JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' ); //Import filesystem libraries. Perhaps not necessary, but does not hurt jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.user.user'); //First we set up parameters $searchpath = JPATH_BASE . DS . "upload"; //Then we create the subfolder called png if ( !JFolder::create($searchpath . DS ."Images") ) { //Throw error message and stop script } //Now we read all png files and put them in an array. $png_files = JFolder::files($searchpath,'.png'); //Now we need some stuff from the JFile:: class to move all files into the new folder foreach ($png_files as $file) { JFile::move($searchpath. DS . ".png" . $file, $searchpath . DS. "Images" . $file); } //Lastly, we are moving the complete subdir to the root of the component. if (JFolder::move($searchpath . DS. "Images",JPATH_COMPONENT) ) { //Redirect with perhaps a happy message } else { //Throw an error } } ?> Only error i get is Notice: Use of undefined constant JPATH_COMPONENT - assumed 'JPATH_COMPONENT' in /upload.php on line 70. I have used and adapted multiple php code so any help would be appreciated. Or if you can point me to where i can find the answer that would be brilliant Hey guys, Anyone who's used Joomla will know they have a very snazzy system for allowing the user to reorder the "order" field in any given table. You know the one, the blue arrows pointing up and down to move the row up or down. I wanna implement something similar in my own sites CMS, does anyone know a good script to handle it? I'm using the J2Store add-on for Joomla. The store prints out a invoice and I am editing what prints out. Right now it prints out each item ordered and the 'options' with that item. (Ex. You can order a Large shirt the options are its a t-shirt and blue.)
What I'm trying to do is make a list of all the material ('options') and quanities in each order.
Below is the section of code I have been working with. I added '<?php echo count($item); ?>' to the code but it just lists the 'options' then a 1 after, but only for one item in the order.
The J2Store support told me this:
"
first you need to decode the $item->orderitem_attributes Then you need to parse through the array and get the options in a required format by sorting and using multiple loops. Then count each option. Example count($array['large']); " <?php if(!J2StoreOrdersHelper::isJSON(stripslashes($item->orderitem_attribute_names))): ?> <?php if (!empty($item->orderitem_attribute_names)) : ?> <span><?php echo $item->orderitem_attribute_names; ?></span> <?php endif; ?> <br /> <?php else: ?> <!-- since 3.1.0. Parse attributes that are saved in JSON format --> <?php if (!empty($item->orderitem_attribute_names)) : ?> <?php //first convert from JSON to array $registry = new JRegistry; $registry->loadString(stripslashes($item->orderitem_attribute_names), 'JSON'); $product_options = $registry->toObject(); ?> <?php foreach ($product_options as $option) : ?> - <small> <?php echo JText::_($option->name); ?>: <?php echo JText::_($option->value); ?> <?php echo count($item); ?> <?php if(isset($option->option_sku) && JString::strlen($option->option_sku) > 0):?> (<?php echo JText::_('J2STORE_SKU'); ?> : <?php echo $option->option_sku; ?>) <?php endif; ?> </small><br /> <?php endforeach; ?> <br/> <?php endif; ?> <?php endif; ?> Edited by Zane, 23 May 2014 - 11:59 AM. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=306933.0 HI All,
I need some suggestions on how to proceed on with component development. and any logic code or similar coding will be very much appreciated.
The component should display the list of contents displaying some columns from a table(ie.,scncontent) from database similar to web links component along with the tool bar (new,edit,publish,unpublish,trash etc., actions ) and with pagination also . This component should be designed with MVC architecture. On clicking new or edit icons, a form should be opened and data should be saved or updated to database.
I'm trying to implement a library which was written for PSR-0 compliant autoloading in my joomla project. However joomla 2.5 does not support PSR-0 autoloading so I figured that I would have to write my own implementation.
Since I want to use my classes across my entire joomla installation I decided to write a plugin which registers the classes onAfterInitialise() but this is where it goes wrong: it overrides joomla's autoloading methods.
The library i'm trying to implement is located at libraries/Zoho/CRM/ZohoClient.php with several subfolders. Everything is namespaced with accordance to PSR-0 so starting with: \Zoho\CRM.
How do I register the classes in such a way that I can use them globally across joomla? This is my implementation:
public function onAfterInitialise() { spl_autoload_register(function ($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); }This obviously wont work because it overrides the joomla autoloading function. I'm running php5.3 (5.4 in 3 months) This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=314053.0 I have a php page that is linked to in a Joomla site in a Wrapper. I want to be able to block access to a php page unless it was called by a link in the main menu. I figured I could use $_SERVER['HTTP_REFERER'] to accomplish this like so: Link from Main Menu -> top_secret.php Code: [Select] <?php //the following is placed in the header of top_secret.php web page $page1 = 'http://myweb.com/index.php?option=com_wrapper&view=wrapper&Itemid=201';//page that user must come from $menu_link = $_SERVER['HTTP_REFERER'];//page that user comes from if($page1 !== $menu_link) { header('Location: http://myweb.com/error_page.php'); } ?> Thus if some one tries to simply access the top_secret.php with out going through the joomla menu- they will be re-directed to an error page. My question to the guru's is- is this secure or can someone easily get to the top_secret.php without going through the menu. Keep in mind- that the menu the person must use is only accessible from a registered joomla user for that site. Hope that makes sense. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=328109.0 Hi Friends..... I want to implement search indexing (like joomla) in my website. Earlier I develop search from database by "select" statement. But for whole website, I don't have any idea to do it............ Plzzzzzzz Help ??????/// I'll highly oblized to you............. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=346951.0 I want to move a module, as shown in the attached jpeg. I want to move it to the position illustrated by the arrow, and I want to increase it's height so it fills the space but leaving a border. There is no module in the position that I can use, so I have to adjust the html coding (I presume). Can anyone help me with this? I have searched for help and I don't even know which file I need to change - whether it is the css or the html. Cheers, James. |