Jump to content

looping problems


doddsey_65

Recommended Posts

I have a weird problem. I have just made a new file but for some reason its taking about 2 mins to load it. I found out why its taking this long. The file renders a header and then the content, then the footer. However this particular file renders the header on a loop(which isnt what its supposed to do). When it does start loading the actual file the header shows up around 20 times. The general code is the same as other files since i have just started it and every other page works. Its nothing to do with htaccess as i thought it could be because i have removed the rewrite rule and did the normal url query line, but the same thing happens. This is the whole content of the file:

 

<?php
/* ASF A Simple Forum
* (c) ASF A Simple Forum 2010 - 2011
* 
* @licence        http://www.asimpleforum.co.uk/licence
* 
* $page        new_post.php
* $author         Carl Markham
* $created        10/06/2011
*/

define('IN_ASF', true);

include('./includes/initialize.php');

if(isset($_GET['method']))
{
    $method     = $_GET['method'];
    $name         = $_GET['name'];
    
    if($method == 'post')
    {
        $crumbs = array(
            '.'                 => 'Board Index',
            $config['asf_root'].'new_post/post/'.$name => 'New Post - '.$name,
        );

        $template->outputHeader('main_header','New Reply - '.$name,'jQuery_tools,jquery.timeago', 'main', $crumbs);

        $array['topic_name'] = $name;
    }
    
    $template->render('new_post', $array, 'show');
    
    $template->outputFooter(null);
}

 

Im not visiting this file from a link, just adding the url to the address bar directly. the render function and outputHeader and outputFooter functions just call other files to be included, which is what i do with other scripts(they work). So anyone know why this file appears to get looped so many times?

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/238956-looping-problems/
Share on other sites

ive done some testing and narrowed it down to the render method. But i use this method on all of my pages with no problems. So here is the method for you to look at, as you can see, no loops.

 

public function render($file_name, $array, $sidebars = 'show')
    {
        if(file_exists($file_name.'.php'))
        {
            include($file_name.'.php');
        }
        else
        {
            session_start();
    
            $array['sidebars'] = $sidebars;

            $array['board_subtitle'] = $this->vars['settings']['board_sub_name'];
            
            $array['template'] = $this->vars['config']['asf_root'].$this->templatePath;
            $array['board_title'] = $this->vars['settings']['board_name'];
            
            $array['user_real_name'] = $this->user['u_real_name'];
            $array['user_group'] = $this->user['g_title'];
            $array['avatar'] = userClass::createAvatar($this->user['u_avatar']);
            $array['redirect'] = $this->asf->getRedirect();
            $array['root'] = $this->vars['config']['asf_root'];
            
            isset($_SESSION['logged_in']) ? $array['logged_in'] = 'yes' : $array['logged_in'] = 'no';
            
            $content = file_get_contents($this->templatePath.$file_name.'.tpl');
            
            $cache_file = './cache/'.$file_name.'.php';
            
            @$content = preg_replace('|\[\$(.*?)\]|e', '$array["\\1"]', $content);
            $content = preg_replace('|\<asf: if (.*?) (.*?) (.*?)\>|', '<?php if(\'\\1\' \\2 \'\\3\') { ?>', $content);
            $content = preg_replace('|\<\/asf: if\>|', '<?php } ?>', $content);
            $content = preg_replace('|\<asf: else\>|', '<?php } else { ?>', $content);
            $content = preg_replace('|\<asf: sidebar\[(.*?)\]\>|e', '$this->renderSidebar("\\1")', $content);
            
            $open = fopen($cache_file, 'w');
            
            fwrite($open, $content);
            
            include('./'.$cache_file);
        }
    }

 

Link to comment
https://forums.phpfreaks.com/topic/238956-looping-problems/#findComment-1227847
Share on other sites

Archived

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.