-2

I've got an HTML file that looks like this called login.php

     <div class="modal fade" id="modal_login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
  <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Login</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-sm-12 col-md-8 col-md-offset-2">
              <h1 class="text-center login-title">Sign in to Hawiak.nl</h1>
              <div class="account-wall">
                  <img class="profile-img" src="" alt="">
                  <form class="form-signin" method="post" action="<?php echo $pages->get("/login/")->url; ?>">
                    <input type="text" name="username" class="form-control" placeholder="Username" required autofocus>
                    <input type="password" name="password" class="form-control" placeholder="Password" required>
                    <button class="btn btn-lg btn-primary btn-block" type="submit">
                        Sign in</button>
                    <label class="checkbox pull-left">
                      <input type="checkbox" value="remember-me">
                        Remember me
                    </label>
                    <a href="#" class="pull-right need-help">Need help? </a><span class="clearfix"></span>
                  </form>
              </div>
              <a href="#" class="text-center new-account">Create an account </a>
          </div>
      </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
  </div>
</div>

But if i use this script:

   foreach($this->snippets as $key => $snippet){
            if(file_exists('snippets/' . $snippet)){
                echo 'test';
                ob_start();
                include('snippets/' . $snippet);
                $$key = ob_get_clean();
                var_dump($$key);
            }else{
                //snippet doesn't exist
                echo $snippet . ' does not exist!' . '<br />';
            }

        }

To loop through an array that looks like array('login'=> 'login.php', 'navbar'=> 'navbar.php') then it only displays the following html:

  <div class="modal fade" id="modal_login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-  hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">Login</h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-sm-12 col-md-8 col-md-offset-2">
                    <h1 class="text-center login-title">Sign in to Hawiak.nl</h1>
                    <div class="account-wall">
                        <img class="profile-img" src="" alt="">

Why?

And most importantly how do i fix this?

zzlalani
  • 22,960
  • 16
  • 44
  • 73
Hawiak
  • 553
  • 1
  • 9
  • 32

2 Answers2

1

you call ob_end_flush(),

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

 ob_start — Turn on output buffering

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

Krish R
  • 22,583
  • 7
  • 50
  • 59
1

Your Sript crashes somewhere at the line $pages->get("/login/")->url, but we don´t have any more information on that getter.

Please enter a die('line:' . __LINE__) at the top of your getter and move it further down till you can reproduce the error. That way you find the errorneous line.

Zsolt Szilagyi
  • 4,741
  • 4
  • 28
  • 44