Mr.Victor Posted January 1, 2010 Share Posted January 1, 2010 I'm having an issue with a php include I added to a web page. I have several php includes on this webpage and they are formatted the same exact way. It was working and for some reason it is no longer working now. I'm not sure what happened. I view the source code of the webpage and the code ends just before the php include. I have tried to include the same file in other pages also with no success so I'm guessing the issue must be in the code of the included php file. When I browse to the actual php file it displays properly. When I paste the php code directly into the web page it displays properly. I am racking my brain here. I have spent hours trying to figure out what is wrong and I can't. Please help. php file displaying properly when browsed to directly: http://www.metrowestpoker.com/includes/api/ChipLeaders.php the php code in that file: <?php $topcount = 20; // display top 10 or use any number you like include "API.php"; // API $url and $pw values set here // Fetch the Site Name using the SystemGet API command. $params = "Password=" . $pw . "&Command=SystemGet&Property=SiteName"; $api = Poker_API($url,$params,true); $result = $api["Result"]; if ($result == "Error") die("Error: " . $api["Error"]); $sitename = $api["Value"]; // Fetch the list of players using the AccountsList API command. $params = "Password=" . $pw . "&Command=AccountsList&Fields=Player,Balance"; $api = Poker_API($url,$params,true); $result = $api["Result"]; if ($result == "Error") die("Error: " . $api["Error"]); // Iterate through the players in the response and create a associative // chips array keyed on player name. $accounts = $api["Accounts"]; $chips = Array(); for ($i = 1; $i <= $accounts; $i++) { $player = $api["Player" . $i]; $chips[$player] = $api["Balance" . $i]; } // Sort array in decending order. arsort($chips); // Display results in an html table. echo "<table border='1' cellspacing='0' cellpadding='5'>\r\n"; echo "<tr><th colspan='3'>$sitename - Chip Leaders</th></tr>\r\n"; echo "<tr><th>Rank</th><th>Player</th><th>Balance</th></tr>\r\n"; $rank = 0; foreach ($chips as $p => $c) { $rank++; echo "<tr><td>$rank</td><td>$p</td><td>$c</td></tr>\r\n"; if ($rank == $topcount) break; } echo "</table><br>\r\n"; ?> here is the page with the above code pasted directly in (working fine...click on the online leaderboard tab): http://www.metrowestpoker.com/leaderboard2.php now here is the page with the above code in file ChipLeaders.php put in the includes/api/ folder (view the source to see the html cuts off where the include should begin): http://www.metrowestpoker.com/leaderboard.php here is a code snippet from the above page: <!--Tab2--> <div class="TabbedPanelsContent"> <h4 align="center">MWPT Online Hold'em - Monthly Top 20</h4> <p align="center"> <?php require 'includes/api/ChipLeaders.php'; ?> </p> </div> I feel like I looked over everything but can't figure it out. It's driving me nuts. Please help. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/ Share on other sites More sharing options...
arbitter Posted January 1, 2010 Share Posted January 1, 2010 I don't know if this will help, but I've always formatted them like this <?php include("API.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-986866 Share on other sites More sharing options...
Mr.Victor Posted January 1, 2010 Author Share Posted January 1, 2010 I tried that earlier. It didn't make a difference but I do appreciate the reply anyhow. Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-986875 Share on other sites More sharing options...
BK87 Posted January 1, 2010 Share Posted January 1, 2010 try.... error_reporting (E_ALL); right after <?php then post an error Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-986876 Share on other sites More sharing options...
tryingtolearn Posted January 1, 2010 Share Posted January 1, 2010 Just a stab but if it works pasted directly in page located in the root dir but doesnt when its in the includes but both times your are calling api.php then that tells me that api.php is in the root dir not the includes dir. Wouldnt you need to change that path? Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-986879 Share on other sites More sharing options...
Mr.Victor Posted January 1, 2010 Author Share Posted January 1, 2010 try.... error_reporting (E_ALL); right after <?php then post an error like this? <?php error_reporting (E_ALL); require 'includes/api/ChipLeaders.php'; ?> Also, I tried putting the include statement ( in another file and now it displayed like it should but still won't in the original web page. Man this has me so confused. Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-986887 Share on other sites More sharing options...
Mr.Victor Posted January 2, 2010 Author Share Posted January 2, 2010 Just a stab but if it works pasted directly in page located in the root dir but doesnt when its in the includes but both times your are calling api.php then that tells me that api.php is in the root dir not the includes dir. Wouldnt you need to change that path? Dreamweaver automatically updates links when the code calls it from the root dir...api.php is definitely in the includes/api/ folder. Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-986947 Share on other sites More sharing options...
Mr.Victor Posted January 2, 2010 Author Share Posted January 2, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-987226 Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2010 Share Posted January 2, 2010 should be a path problem try putting the following lines on the start of your script ini_set('display_errors', '1'); error_reporting(E_ALL); and tell us if you see any errors Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-987230 Share on other sites More sharing options...
Mr.Victor Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks Rajiv! Making some progress. Here is the error i got: Fatal error: Cannot redeclare poker_api() (previously declared in /services2/webpages/util/m/w/mwpl.site.aplus.net/public/includes/api/API.php:6) in /services2/webpages/util/m/w/mwpl.site.aplus.net/public/includes/api/API.php on line 47 Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-987264 Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2010 Share Posted January 2, 2010 that means the page has already been included, remove it the include from ChipLeaders.php, or if you want it to be accessed directly also use require_once and include_once instead of include and require Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-987266 Share on other sites More sharing options...
Mr.Victor Posted January 2, 2010 Author Share Posted January 2, 2010 I changed: include "API.php"; to: include_once "API.php"; in the ChipLeaders.php file and that worked out! Sweeeet! I'm just curious why that did it. There is no other: include "API.php"; anywhere else in the ChipLeaders.php so I'm not sure why it's saying it's calling it twice. Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-987291 Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2010 Share Posted January 2, 2010 you must be including ChipLeaders.php in another file which has included API.php causing it to throw the error Quote Link to comment https://forums.phpfreaks.com/topic/186872-why-is-this-php-include-not-working/#findComment-987299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.