Jump to content

Curl cookie problem


sfraise

Recommended Posts

Here is a brief description of what I'm doing...

I have a very large complex social networking site built on the Joomla CMS with many one off components and modules and many heavily modified ones.

One thing I'm doing is using a module called mod_component built by jomexperts (their website forum doesn't work so no help there) which allows you to load a component within a module, in this case it's loading the wall component within a module position called in a tab on the community builder profiles. This module is modified a bit in order to include the user id in the internal url it creates in order to determine if you are viewing your own profile or someone else's and to determine who's wall it is.

 

This all worked like a champ until a couple of weeks ago when for whatever reason the server was unresponsive for a few minutes. When it came back up the wall no longer would load, so basically the mod_component module simply stopped working. I racked my brain for a couple of days trying to figure out what was causing it when it just suddenly started working again on it's own. It worked fine again until last night, according to my host there was a large scale ddos attack causing the server to be unresponsive again for a few minutes, when it came back up the wall no longer loaded again.

 

I'm using a dual dedicated server set up with the web files on one server and the other server strictly dedicated to the database, don't think this matters in this case but figured I'd mention it.

 

On to the heart of the problem...

So I began going through the module code and doing an echo of each variable starting at the top of the file. It works fine until I get to a little bit of curl code that writes the session id to a cookie. Doing a die("curl"); call right before that code causes the page to break and respond with curl. I tweaked the code a bit to specify the path to cookiejar and the code creates the file, but is unable to write to it. Now I created an exact mirror instance of this site on a separate server and it works fine, on that server it can both create the file and write to it without any problem.

 

So...

Since this worked on this server fine until it went down briefly last night, then stopped working when it came back up, something changed somewhere somehow either with permissions or something else that would cause curl to not be able to write. What baffles me is it's able to create the file, just not write to it?????? Does anyone have any idea on what could be happening here? I thought maybe it was a case of a curl session not being closed when the server went down locking it up, but I cleared the php sessions, joomla sessions, cache, and rebooted the machine and it still didn't work so I'm not sure on that theory. I really really really need a genius here to point me the right direction lol.

 

Here's a copy of the modules main file, commented out parts of the curl code are what I was using to determine if it could both create and write a file:


<?php
/** 
* Component Loader 
* @version : 1.0.1 
* @package : Component Loader 1.0.1 
* @author : JomExperts 
* @Copyright : Copyright © 2009 by Jomexperts.com 
* @license : Component Loader 1.0.1 is Free Software released under the GNU/GPL License. 
*/ 


// no direct access
defined('_JEXEC') or die ('Restricted access');
/* Getting Parameters */
$component= $params->get('component','');
$view= $params->get('views','');
$custom=$params->get('custom','');
$auto=$params->get('autojscss','0');
$js=$params->get('customjs','');
$css=$params->get('customcss','');
$head_js=$params->get('custombodyjs','');
$head_css=$params->get('custombodycss','');
/* End of Parameters */

$type=array();
$layout=array();
if($component!=''){
/* Getting components parameters like task, view, layout, etc. */
$re1='.*?';	
$re2='(?:[a-z][a-z0-9_]*)';	
$re3='.*?';	
$re4='((?:[a-z][a-z0-9_]*))';	
$re5='.*?';	
$re6='((?:[a-z][a-z0-9_]*))';	
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $view, $matches)){
	$type=$matches[1];
	$layout=$matches[2];
}
/* end */

/* Creating URL */
$user_id = $_GET['user'];
$url=JURI::root().'index.php?'.$component.'&tmpl=component&print=1&wuid='.$user_id.'';
for($i=1;$i<count($type);$i++){
	$url.='&'.$type[$i].'='.$layout[$i];
}
$url.=$custom;
/* End */

/* Getting current joomla Session ID */
$session=&JFactory::getSession();
$session_id=$session->getId();
/* End */

/* Starting curl session */
/* $ckfile = tempnam ("/tmp", session_name().'='.$session_id ); */
$c_open=curl_init();
/* curl_setopt($c_open, CURLOPT_COOKIEJAR, $ckfile); */
curl_setopt($c_open, CURLOPT_URL , $url);
curl_setopt($c_open, CURLOPT_HEADER, 1);
curl_setopt($c_open, CURLOPT_RETURNTRANSFER, 1); 
/*	curl_setopt ($c_open, CURLOPT_COOKIEFILE, $ckfile); */
curl_setopt ($c_open, CURLOPT_COOKIE, session_name().'='.$session_id );  // Passing session ID.
/*    session_write_close($c_open); */
    $result=curl_exec($c_open);
    curl_close($c_open);
    /* End of curl session */

    $document=&JFactory::getDocument();
    $matches=array();
    if($auto=='0'){
    	$jsarray=explode(',',$js);
    	$cssarray=explode(',',$css);

    	for($i=0;$i<count($jsarray);$i++){
    		$document->addScript($jsarray[$i]);
    	}

    	for($i=0;$i<count($cssarray);$i++){
    		$document->addStyleSheet($cssarray[$i]);
    	}
    	if($head_js!=''){
    		$document->addScriptDeclaration($head_js);
    	}
    	if($head_css!=''){
    		$document->addStyleDeclaration($head_css);
    	}
    } else {
    	/* Using regular expression to match and extract contents between <head> and </head> tag */
    	$pattern = "/(<HEAD[^>]*>)(.*?)(<\/HEAD>)(.*)/si";
    	$count = preg_match_all($pattern,$result,$matches);
    	if ($count>0) {
    		$head=$matches[2][0];
    	} else {
    		$head='';
    	}

    	/* Using regular expression to match and extract contents between <script> and </script> tag with source */
    	$pattern = '/<script.*src=[\'\"](.*?)[\'\"][^>]*[^<]*(<\/script>)?/i';
    	$count = preg_match_all($pattern,$head,$scripts);
    	if ($count>0)
    	foreach ($scripts[1] as $script) {
    		$document->addScript($script);
    	}

    	/* Using regular expression to match and extract contents between <script> and </script> tag without source */
    	$pattern = '/<script[^>]*>(.*?)<\/script>/si';
    	$scripts= array();
    	$count = preg_match_all($pattern,$head,$scripts);
    	if ($count>0)
    	foreach ($scripts[1] as $script) {
    		if (trim($script)!='')
    		$document->addScriptDeclaration($script);
    	}

    	/* Using regular expression to match and extract contents link tag */
    	$pattern = '/<link.*href=[\'\"](.*?)[\'\"][^>]*[^<]*(<\/link>)?/i';
    	$count = preg_match_all($pattern,$head,$styles);
    	if ($count>0)
    	for ($x=0;$x<$count;$x++) {
    		if ((preg_match('/type=[\'"]text\/css[\'"]/i', $styles[0][$x])>0)||(preg_match('/rel=[\'"]stylesheet[\'"]/i', $styles[0][$x])>0))
    		$document->addStyleSheet($styles[1][$x]);
    	}

    	/* Using regular expression to match and extract contents between <style> and </style> */
    	$pattern = '/<style[^>]*>(.*?)<\/style>/si';
    	$styles = array();
    	$count = preg_match_all($pattern,$head,$styles);
    	if ($count>0)
    	foreach ($styles[1] as $style) {
    		if (trim($style)!='')
    		$document->addStyleDeclaration($style);
    	}
    }


    /* Using regular expression to match and extract contents between <body> and </body> tag */
    $pattern='~<body[^>]*>(.*?)</body>~si';

    if(preg_match_all($pattern,$result,$matches)){
    	echo ($matches[1][0]);
    } else {
     	echo "We're working on the wall, please check back later.";
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.