executing some code before anything else runs

Permalink
Hi, I'm writing a cart for a customer and the way this particular payment gateway works (DPS - New Zealand) I need to send them a session id and then when the transaction is approved they reply with that session id and I initialize the session based on that id. I've done it lots of times in the CMS I was using before and it works like a charm.
Now I'm porting the cart to concrete5 and I want to put it all in a package.
The only problem is that I couldn't find anywhere to set the session_id at startup from the package.
The way I fixed it now, is adding the right bit of code to site.php but I know I shouldn't be adding code there, and it means that the cart package needs to rely on people remembering to enter the hack in the site.php file, which is something I don't want.
Any suggestions?

matogertel
 
andrew replied on at Permalink Reply
andrew
This would be a nice developer feature to add to our feature requests tracker.
ijessup replied on at Permalink Reply
ijessup
Though this wouldn't be my favorite solution, but it would solve the problem of people manually editing the site.php file.

You would override the install function and have the line of code added to the site.php file automatically.

Assuming you have write access...
Something like:
$file = fopen($_SERVER['DOCUMENT_ROOT']."config/site.php", "a+");
$line = "ADD THIS LINE OF CODE";
fwrite($file, $line);
fclose($file);

If you don't have write access, you could:

Check "site.php" Permissions
Temp chmod "site.php"
Write line of code
Return permissions to original

Very hacky... but should do the trick. Just provide the user with a way to input the ID and a username and password if the file needs write permission.
matogertel replied on at Permalink Reply
matogertel
Actually, version 5.2 final has the on_start function in the package controller that gets executed right before the session starts, so that will do the trick! (Haven't tried it yet...)