-2

So I wanted to add in a test whether cookies are enabled for my website. and Some reason now the page won't load even after I removed it from the code.

The errors I'm getting.

Warning: require_once(../system/init.php): failed to open stream: No such file or directory in /index.php on line 2

Fatal error: require_once(): Failed opening required '../system/init.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /index.php on line 2

Here is code with script still in

<?php
require_once 'system/init.php';

include 'includes/head.php';
include 'includes/navigation.php';
include 'includes/headerfull.php';
include 'includes/leftbar.php';


$sql= "SELECT * FROM products WHERE featured = 1";
$featured = $db->query($sql);
?>

<!-- main content -->
<div id="maincontent" class="col-md-8" style=" ">
 <div class="row">
  <h2 class="text-center">Feature Products</h2>
    <?php while($product = mysqli_fetch_assoc($featured)) :  ?>

       <div class="col-sm-3 text-center">
          <h4><?= $product['title']; ?></h4>
          <img src="<?= $product['image']; ?>" alt="<?= $product['title']; ?>" class="img-thumb"/>

          <p class="price">Our Price: <?= $product['price']; ?></p>
          <button type="button" class="btn btn-sm btn-success" onclick="detailsmodal(<?= $product['id']; ?>)">Details</button>
       </div>
    <?php  endwhile; ?>

 </div>
</div>



<script type="text/javascript">
if (navigator.cookieEnabled) return true;

// set and read cookie
document.cookie = "cookietest=1";
var ret = document.cookie.indexOf("cookietest=") != -1;

// delete cookie
document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";

return ret;
</script>

<?php
include 'includes/rightbar.php';
include 'includes/footer.php';
?>

edit: The possible duplicate did not work. The code on the page worked fine before I added what is in the tags. after I tried them and they did not work I reverted back to the working copy and it still does not work.

Edit 2:

So I really have no idea what happened now. After searching and looking for answers I refresh one more time and now its magically working? Can someone explain this? I had refreshed 20+ times by that point becuase I wondered if the jscript messed up my cookie.

ikazuchi
  • 13
  • 3
  • 2
    These are pretty simple errors to diagnose.... – WillardSolutions May 11 '16 at 17:14
  • 1
    Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Chris May 11 '16 at 17:16
  • Nope, not the duplicate. It may be simple for you @EatPeanutButter but I am still new to this. This is my first Fully functional ecommerce site and could use all the help and knowledge I can get. – ikazuchi May 11 '16 at 17:23
  • Yes, it is a duplicate. It's the exact error you are getting. – Chris May 11 '16 at 17:24
  • Do you have a backup of your file? – j08691 May 11 '16 at 17:24
  • I just meant as in the link provided did not work? Chris . Stack told me to edit it if it wasn't the solution. @j08691 I did and that is what I reuploaded. but it changed nothing. So I removed my cookie and reloaded a few times and still nothing. I found other webpages worked though. returned to the index and still didn't work. 5 refreshes later doing absolutely nothing and its working again. T_T I'm so confused. – ikazuchi May 11 '16 at 17:29

3 Answers3

2

I think it's pretty clear that

require_once 'system/init.php';

causes error because that file is not found in server. Either invalid URL (most likely) or typo. Please double check it.

Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54
1

This is clear that you use a right syntax of require_one. You need to just check that path of a file which you wrote in required_one that it is correct or not and file permission of your file.

Tony
  • 204
  • 1
  • 4
1

As stated above the path to the init.php is not correct. Probably you moved anything away. Please check that: you are requiring 'system/init.php'; but your site is searching for '../system/init.php'

Iamnino
  • 360
  • 1
  • 4
  • 17