hi
So ive deployed a small website i worked on, and before deployemnt on Amazon web services, i was of course testing everything on localhost. after seeing that things are working on localhost, i changed the localhost to the deployment link provided on AWS and things looked fine and all except that some pages were giving me annoying slim application errors since yesterday.
of those errors is the "if (key_array_exists)" which i ended up commenting out in order to finally be logged in. then i tried viewing the "team documents" functionality i have and when it goes to that page, i got some slim errors regarding "file_get_contents".
I read up on this everywhere and people suggested to use urlencode/rawurlencode since online hosting doesnt interpret the url the same way as running on localhost. but the issue was that most examples were shown using it with spaces as special character problem, but my url doesnt have spaces so i didnt know where to even implmenet this in the url i have.
so i took on the other suggestions of using cURL. I even tested cURL on the localhost and it works...but again on the AWS server it doesnt!
I am getting this error for the AWS hosted version:
Message: Invalid argument supplied for foreach()
this is the code its talking about:
<section>
<?php
/* $raw = file_get_contents("http://cosoft.us-east-1.elasticbeanstalk.com/cosoft/mywiki/api.php?action=query&list=allpages&format=json");
$pages_response = json_decode($raw, true);
$pages_array = $pages_response["query"]["allpages"];
$page_titles = []; */
$raw = 'http://cosoft.us-east-1.elasticbeanstalk.com/cosoft/mywiki/api.php?action=query&list=allpages&format=json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $raw);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
$pages_response = json_decode($data, true);
$pages_array = $pages_response["query"]["allpages"];
$page_titles = [];
require_once("domainlogic/wiki_api.php");
// echo nl2br("the logged name is " .$loggedName. "\n");
foreach ($pages_array as $page)
{
// We have the User Id of the wiki doc ($wikiUserId);
// if the revision user field matches the userId, we'll show the doc.
// otherwise, we won't.
$name = $page["title"];
$pageAuthor = WIKI_API::getRevisionIdForPage($name);
//echo nl2br("page title: ".$name." -- comparing pageAuthor: ".$pageAuthor." against teamId: ".$wikiUserId. "\n");
//echo nl2br(" the pageAuthor is " .$pageAuthor. "\n");
//if ($pageAuthor == $loggedName) {
// we have a match.
//echo "we have a match for ".$name. " it is ".$pageAuthor;
//echo " A " .$wikiUserId. " is the wikiuserID " .$loggedName. " is the logged name" .$teamName. "is the logged team name ";
//echo " The revision history includes " .$pageAuthor;
array_push($page_titles, $name);
// }
}
$baseUrl = './mywiki/index.php/';
if (count($pages_array) == 0 || is_null($pages_array)) {
echo "<h1 id='noDocMessage'>You have no documents</h1>";
}
?>
<ul id="gallery">
<?php foreach( $page_titles as $title): ?>
<li class="documentLI">
<a href="<?= $baseUrl ?><?= $title ?>">
<img src="images/todoDoc.png" alt="Document Image" class="documentImage">
</a>
<div>
<a href="<?= $baseUrl ?><?= $title ?>"><p><?= $title ?></p></a>
</div>
<div>
<a href="./deletePage?title=<?= $title ?>">
<!-- <img src="images/delete.png" alt="delete" class="deleteImage"> -->
</a>
</div>
</li>
<?php endforeach; ?>
</ul>
</section>
its talking specifically about this piece here: foreach ($pages_array as $page)
I dont know why its not giving issues with localhost but with the AWS it is?!
Im extremely tired of chasing around with these issues and I want this to work finally.
Any help is appreciated thanks