Jump to content

Curl cookie problem


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.



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:

* 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','');
/* End of Parameters */

/* Getting components parameters like task, view, layout, etc. */
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $view, $matches)){
/* end */

/* Creating URL */
$user_id = $_GET['user'];
/* End */

/* Getting current joomla Session ID */
/* End */

/* Starting curl session */
/* $ckfile = tempnam ("/tmp", session_name().'='.$session_id ); */
/* 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); */
    /* End of curl session */



    } 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) {
    	} else {

    	/* 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) {

    	/* 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)!='')

    	/* 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))

    	/* 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)!='')

    /* Using regular expression to match and extract contents between <body> and </body> tag */

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

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.