Если вы не слишком озабочены подделкой URL, я бы добавил в URL переменную-счетчик, которая передается методу addSection (), например:
function addSection($count) {
if ($count >= 3) { return $count; }
global $compid;
$sectionOb = new Item();
$sectionOb->i_id_pk = $sectionOb->newId();
$sectionOb->i_mod_comp_id_fk = $compid;
$sectionOb->c_titel = '';
$sectionOb->c_content = '';
$sectionOb->i_sort = $sectionOb->newSort($compid);
$sectionOb->insert();
// Return incremented count
return $count + 1;
}
// Retrieve the last count from the URL
$count = isset($_GET['count']) ? intval($_GET['count']) : 0;
// Increment the count if the action is add and the addSection method suceedes
if($action == 'add') {
$count = addSection($count);
}
// Add count to the URL so we know what it is
<a href="<?php echo $_SERVER['REQUEST_URI'] ?>&action=add&count=<?php echo $count; ?>" />new section</a>