finestice Posted February 25, 2011 Share Posted February 25, 2011 Hi peeps iv been trying to figure out this but i cant see it....its probably obvious!!! in the $header variable the include files dont show... any ideas here the php code <? session_start(); ?> <link href="/styles/main.css" rel="stylesheet" type="text/css" /> <? //get data $button = $_GET['submit']; $search = $_GET['search']; $search = strtoupper($search); $header = ("<table width='100%' border='0' height='80' cellpadding='4' bgcolor='#000000' > <tr> <td width='39%' height='76' valign='top'><p><span class='stigrosheadfont'><strong>www.StigRos.com</strong></span><strong><span class='headnocrap'><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href='http://mysite' class='headerlinkcolor'>Home</a> | <a href='register.php' class='headerlinkcolor'>Register</a> | <a href='#' class='headerlinkcolor'>Contact us</a></strong></td> <td width='47%' valign='bottom'><p class='normalblacktext'>You are currently logged in, <b>$_SESSION[username]</b></td> <td width='14%' valign='top'><div align='center'> <div align='center'><span class='headfont'><strong>Disclaimer</strong></span></div> <div align='center'> <? include_once 'countertest.php'; ?> <? date('F d, Y'); ?></div></td> </tr> </table>"); $s = $_GET['s']; if (!$s) $s = 0; $e = 10; // Just change to how many results you want per page $next = $s + $e; $prev = $s - $e; if (strlen($search)<=2) echo "Must be greater then 3 chars $user"; else { echo $header; echo " <form action='search.php' method='GET'> <center> <br> <input name='search' type='text' class='blacktext' size='50'> <input name='submit' type='submit' class='blacktext' value='Search Film'></font></p> </center> </form> "; //connect to db include('db.php'); //explode out search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "keyword LIKE '%$search_each%'"; else $construct .= " OR keyword LIKE '%$search_each%'"; } //echo outconstruct $constructx = "SELECT * FROM movies WHERE $construct"; $construct = "SELECT * FROM movies WHERE $construct LIMIT $s,$e"; $run = mysql_query($constructx); $foundnum = mysql_num_rows($run); $run_two = mysql_query("$construct"); if ($foundnum==0) echo "No results found for <b>$search</b>"; else { echo "<table bgcolor='#000000' width='80%' height='1px' align='center'><br /></table><table bgcolor='#000000' width='80%' height='10px' align='center'><tr><td><div align='right'><font color='#E6E6E6'>Showing 1-10 of <b>$foundnum</b> results found for <b>$search.</b></font></div></td></tr></table><p>"; echo "<br>"; while ($runrows = mysql_fetch_assoc($run_two)) { //get data $title = $runrows['film']; $desc = $runrows['description']; $url = $runrows['dl_link']; $imdb = $runrows['imdb']; $pic = $runrows['pic']; $film = $runrows['film']; echo "<table width='900' border='1' align='center'> <tr> <td width='229' align='center'><IMG SRC='$pic'></td> <td class='blacktext' width='655' align='center'><b>$film</b><br /><br />$desc<br /><br /><a href='$url' target='_blank'><b>Download Now</b></a> | <a href='$imdb' target='_blank'><b>IMDb</b></a></td> </tr> </table> "; } ?> <table width='100%'> <tr> <td> <div align="center"> <?php if (!$s<=0) echo "<a href='search.php?search=$search&s=$prev'>Prev</a>"; $i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; } if ($s<$foundnum-$e) echo "<a href='search.php?search=$search&s=$next'>Next</a>"; } } ?> </div> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/ Share on other sites More sharing options...
swharrell Posted February 25, 2011 Share Posted February 25, 2011 You have nested php tags. <? include_once 'countertest.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179702 Share on other sites More sharing options...
finestice Posted February 25, 2011 Author Share Posted February 25, 2011 how do i include the file iv removed the <? ?> tags but still doesnt show the date etc!! Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179745 Share on other sites More sharing options...
UQ13A Posted February 25, 2011 Share Posted February 25, 2011 how do i include the file iv removed the <? ?> tags but still doesnt show the date etc!! I think swharrell means use the full open and close tags <?php ?> Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179746 Share on other sites More sharing options...
finestice Posted February 25, 2011 Author Share Posted February 25, 2011 <table width='100%' border='0' height='80' cellpadding='4' bgcolor='#000000' > <tr> <td width='39%' height='76' valign='top'><p><span class='stigrosheadfont'><strong>www.StigRos.com</strong></span><strong><span class='headnocrap'><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href='http://stigros.com' class='headerlinkcolor'>Home</a> | <a href='register.php' class='headerlinkcolor'>Register</a> | <a href='#' class='headerlinkcolor'>Contact us</a></strong></td> <td width='47%' valign='bottom'><p class='normalblacktext'>You are currently logged in, <b>$_SESSION[username]</b></td> <td width='14%' valign='top'><div align='center'> <div align='center'><span class='stigrosheadfont'><strong>Disclaimer</strong></span></div> <div align='center'> <? include_once 'countertest.php'; ?> <? echo date('F d, Y'); ?></div></td> </tr> </table> <form action='search.php' method='GET'> <center> <br> <input name='search' type='text' class='blacktext' size='50'> <input name='submit' type='submit' class='blacktext' value='Search Film'></font></p> </center> </form> "; //connect to db include('connect.php'); the countertest php is : <?php $dataFile = "visitors.txt"; $sessionTime = 30; //this is the time in **minutes** to consider someone online before removing them from our file //Please do not edit bellow this line error_reporting(E_ERROR | E_PARSE); if(!file_exists($dataFile)) { $fp = fopen($dataFile, "w+"); fclose($fp); } $ip = $_SERVER['REMOTE_ADDR']; $users = array(); $onusers = array(); //getting $fp = fopen($dataFile, "r"); flock($fp, LOCK_SH); while(!feof($fp)) { $users[] = rtrim(fgets($fp, 32)); } flock($fp, LOCK_UN); fclose($fp); //cleaning $x = 0; $alreadyIn = FALSE; foreach($users as $key => $data) { list( , $lastvisit) = explode("|", $data); if(time() - $lastvisit >= $sessionTime * 60) { $users[$x] = ""; } else { if(strpos($data, $ip) !== FALSE) { $alreadyIn = TRUE; $users[$x] = "$ip|" . time(); //updating } } $x++; } if($alreadyIn == FALSE) { $users[] = "$ip|" . time(); } //writing $fp = fopen($dataFile, "w+"); flock($fp, LOCK_EX); $i = 0; foreach($users as $single) { if($single != "") { fwrite($fp, $single . "\r\n"); $i++; } } flock($fp, LOCK_UN); fclose($fp); if($uo_keepquiet != TRUE) { echo '<div style="padding:5px; margin:auto; background-color:#000"<b>' . $i . ' visitors online</div>'; } ?> dont know if the counteretest.php file is needed but it wont display in the include bit iv try incasing it in <?php ?> and <? ?> still dont dont... the header should look like this http://stigros.com Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179748 Share on other sites More sharing options...
MatthewJ Posted February 25, 2011 Share Posted February 25, 2011 $header = "<table width='100%' border='0' height='80' cellpadding='4' bgcolor='#000000' > <tr> <td width='39%' height='76' valign='top'><p><span class='stigrosheadfont'><strong>www.StigRos.com</strong></span><strong><span class='headnocrap'><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href='http://mysite' class='headerlinkcolor'>Home</a> | <a href='register.php' class='headerlinkcolor'>Register</a> | <a href='#' class='headerlinkcolor'>Contact us</a></strong></td> <td width='47%' valign='bottom'><p class='normalblacktext'>You are currently logged in, <b>" . $_SESSION['username'] . "</b></td> <td width='14%' valign='top'><div align='center'> <div align='center'><span class='headfont'><strong>Disclaimer</strong></span></div> <div align='center'>" . include_once('countertest.php') . " " . date('F d, Y') . "</div></td> </tr> </table>"; Try replacing the $header chunk with this. Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179751 Share on other sites More sharing options...
samshel Posted February 25, 2011 Share Posted February 25, 2011 1) make sure countertest.php is in the same folder. 2) Print something at the top of countertest.php just after php tag to see if it is including 3) Write a test php file with only include statement for countertest.php to make sure that works Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179753 Share on other sites More sharing options...
MatthewJ Posted February 25, 2011 Share Posted February 25, 2011 I mean no offense, but if you look... he has opening and closing php tags within a string where he is trying to do the include... strangely enough, PHP tags don't work when they're within a string Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179759 Share on other sites More sharing options...
swharrell Posted February 25, 2011 Share Posted February 25, 2011 Set the countertest.php as a variable and then call the variable in the table: <? session_start(); ?> <link href="/styles/main.css" rel="stylesheet" type="text/css" /> <? //get data $button = $_GET['submit']; $search = $_GET['search']; $search = strtoupper($search); $countertest = include_once 'countertest.php'; $header = ("<table width='100%' border='0' height='80' cellpadding='4' bgcolor='#000000' > <tr> <td width='39%' height='76' valign='top'><p><span class='stigrosheadfont'><strong>www.StigRos.com</strong></span><strong><span class='headnocrap'><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href='http://mysite' class='headerlinkcolor'>Home</a> | <a href='register.php' class='headerlinkcolor'>Register</a> | <a href='#' class='headerlinkcolor'>Contact us</a></strong></td> <td width='47%' valign='bottom'><p class='normalblacktext'>You are currently logged in, <b>$_SESSION[username]</b></td> <td width='14%' valign='top'><div align='center'> <div align='center'><span class='headfont'><strong>Disclaimer</strong></span></div> <div align='center'>" . $countertest . "</div></td> </tr> </table>");... If this doesn't work also do what samshel suggested. Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179760 Share on other sites More sharing options...
DavidAM Posted February 25, 2011 Share Posted February 25, 2011 include (and it's siblings) does NOT return the content of the file. It includes the file in the source code as if it was typed there. You cannot "include" inside a string. Assigning "include(filename.php)" to a string does NOT put the code from that file into the string, and it does NOT put any output from that file (i.e. echo, print, or stuff outside of php tags) in the string. Any code will be parsed and executed and any output will be outputted. From the looks of the code you posted, you need to wrap the stuff inside countertest.php in a function, change the echo (at the end) to a return, include the file early in your script, and call the new function in the string assignment. Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179782 Share on other sites More sharing options...
samshel Posted February 25, 2011 Share Posted February 25, 2011 Try This: <? session_start(); ?> <link href="/styles/main.css" rel="stylesheet" type="text/css" /> <? //get data $button = $_GET['submit']; $search = $_GET['search']; $search = strtoupper($search); $s = $_GET['s']; if (!$s) $s = 0; $e = 10; // Just change to how many results you want per page $next = $s + $e; $prev = $s - $e; if (strlen($search)<=2) echo "Must be greater then 3 chars $user"; else { $header = ("<table width='100%' border='0' height='80' cellpadding='4' bgcolor='#000000' > <tr> <td width='39%' height='76' valign='top'><p><span class='stigrosheadfont'><strong>www.StigRos.com</strong></span><strong><span class='headnocrap'><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href='http://mysite' class='headerlinkcolor'>Home</a> | <a href='register.php' class='headerlinkcolor'>Register</a> | <a href='#' class='headerlinkcolor'>Contact us</a></strong></td> <td width='47%' valign='bottom'><p class='normalblacktext'>You are currently logged in, <b>$_SESSION[username]</b></td> <td width='14%' valign='top'><div align='center'> <div align='center'><span class='headfont'><strong>Disclaimer</strong></span></div> <div align='center'>"); echo $header; include_once 'countertest.php'; echo date('F d, Y')."</div></td> </tr> </table>"; echo " <form action='search.php' method='GET'> <center> <br> <input name='search' type='text' class='blacktext' size='50'> <input name='submit' type='submit' class='blacktext' value='Search Film'></font></p> </center> </form> "; //connect to db include('db.php'); //explode out search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "keyword LIKE '%$search_each%'"; else $construct .= " OR keyword LIKE '%$search_each%'"; } //echo outconstruct $constructx = "SELECT * FROM movies WHERE $construct"; $construct = "SELECT * FROM movies WHERE $construct LIMIT $s,$e"; $run = mysql_query($constructx); $foundnum = mysql_num_rows($run); $run_two = mysql_query("$construct"); if ($foundnum==0) echo "No results found for <b>$search</b>"; else { echo "<table bgcolor='#000000' width='80%' height='1px' align='center'><br /></table><table bgcolor='#000000' width='80%' height='10px' align='center'><tr><td><div align='right'><font color='#E6E6E6'>Showing 1-10 of <b>$foundnum</b> results found for <b>$search.</b></font></div></td></tr></table><p>"; echo "<br>"; while ($runrows = mysql_fetch_assoc($run_two)) { //get data $title = $runrows['film']; $desc = $runrows['description']; $url = $runrows['dl_link']; $imdb = $runrows['imdb']; $pic = $runrows['pic']; $film = $runrows['film']; echo "<table width='900' border='1' align='center'> <tr> <td width='229' align='center'><IMG SRC='$pic'></td> <td class='blacktext' width='655' align='center'><b>$film</b><br /><br />$desc<br /><br /><a href='$url' target='_blank'><b>Download Now</b></a> | <a href='$imdb' target='_blank'><b>IMDb</b></a></td> </tr> </table> "; } ?> <table width='100%'> <tr> <td> <div align="center"> <?php if (!$s<=0) echo "<a href='search.php?search=$search&s=$prev'>Prev</a>"; $i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; } if ($s<$foundnum-$e) echo "<a href='search.php?search=$search&s=$next'>Next</a>"; } } ?> </div> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179788 Share on other sites More sharing options...
finestice Posted February 26, 2011 Author Share Posted February 26, 2011 nope not working or not displaying right... ok i was thinking of this. putting my include header at the top of the page...but now its not carrying on with the search....just dispplay no result...ahhhhhhh <? session_start(); ?> <link href="/styles/main.css" rel="stylesheet" type="text/css" /> <? include 'head_loggedin.php'; //get data $button = $_GET['submit']; $search = $_GET['search']; $search = strtoupper($search); $s = $_GET['s']; if (!$s) $s = 0; $e = 10; // Just change to how many results you want per page $next = $s + $e; $prev = $s - $e; if (strlen($search)<=2) echo "Must be greater then 3 chars $user"; else { echo " <form action='search.php' method='GET'> <center> <br> <input name='search' type='text' class='blacktext' size='50'> <input name='submit' type='submit' class='blacktext' value='Search Film'></font></p> </center> </form> "; //connect to db include('connect.php'); //explode out search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "keyword LIKE '%$search_each%'"; else $construct .= " OR keyword LIKE '%$search_each%'"; } //echo outconstruct $constructx = "SELECT * FROM movies WHERE $construct"; $construct = "SELECT * FROM movies WHERE $construct LIMIT $s,$e"; $run = mysql_query($constructx); $foundnum = mysql_num_rows($run); $run_two = mysql_query("$construct"); if ($foundnum==0) echo "No results found for <b>$search</b>"; else { echo "<table bgcolor='#000000' width='80%' height='1px' align='center'><br /></table><table bgcolor='#000000' width='80%' height='10px' align='center'><tr><td><div align='right'><font color='#E6E6E6'>Showing 1-10 of <b>$foundnum</b> results found for <b>$search.</b></font></div></td></tr></table><p>"; echo "<br>"; while ($runrows = mysql_fetch_assoc($run_two)) { //get data $title = $runrows['film']; $desc = $runrows['description']; $url = $runrows['dl_link']; $imdb = $runrows['imdb']; $pic = $runrows['pic']; $film = $runrows['film']; echo "<table width='900' border='1' align='center'> <tr> <td width='229' align='center'><IMG SRC='$pic'></td> <td class='blacktext' width='655' align='center'><b>$film</b><br /><br />$desc<br /><br /><a href='$url' target='_blank'><b>Download Now</b></a> | <a href='$imdb' target='_blank'><b>IMDb</b></a></td> </tr> </table> "; } ?> <table width='100%'> <tr> <td> <div align="center"> <?php if (!$s<=0) echo "<a href='search.php?search=$search&s=$prev'>Prev</a>"; $i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; } if ($s<$foundnum-$e) echo "<a href='search.php?search=$search&s=$next'>Next</a>"; } } ?> </div> </td> </tr> </table> heres the 'head_loggedin.php' file <? session_start(); require_once("connect.php"); // Check his status. if (empty($_SESSION[username])) //not logged in!! { header("Location: login.php"); } ?> <link href="/styles/main.css" rel="stylesheet" type="text/css" /> <table width="100%" border="0" height="80" cellpadding="4" bgcolor="#000000" > <tr> <td width="39%" height="76" valign="top"><p><span class="stigrosheadfont"><strong>www.StigRos.com</strong></span><strong><span class="headnocrap"><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href="http://stigros.com" class="headerlinkcolor">Home</a> | <a href="register.php" class="headerlinkcolor">Register</a> | <a href="#" class="headerlinkcolor">Contact us</a></strong></td> <td width="47%" valign="bottom"><? echo "<p class='normalblacktext'>You are currently logged in, <b>$_SESSION[username]</b>.";?></td> <td width="14%" valign="top"><div align="center"> <div align="center"><span class="stigrosheadfont"><strong>Disclaimer</strong></span></div> <div align="center"> <?php include_once "countertest.php"; ?> <?php echo date("F d, Y"); ?></div></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1179844 Share on other sites More sharing options...
swharrell Posted February 26, 2011 Share Posted February 26, 2011 finestice. I may be wrong (wouldn't be the first time) but in the 10th line of your countertest.php file it appears you are asking if a file does not (!) exist, then open the file. if(!file_exists($dataFile)) { $fp = fopen($dataFile, "w+"); fclose($fp); } Edit: Sorry, my bad. Didn't see the w+. But that does bring up another question, is the file being created? Also, have you looked at the generated code to see if anything is being written from the includes? Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1180027 Share on other sites More sharing options...
finestice Posted February 26, 2011 Author Share Posted February 26, 2011 the countertest.php works fine goto stigros.com to see the header but when try to included it the search.php it shows ok but the search doesnt search properly just always says 'no result found' but if i remove the include file it works!!!! cant figure it out Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1180057 Share on other sites More sharing options...
swharrell Posted February 26, 2011 Share Posted February 26, 2011 OK. Let's attack this from a different angle. When I look at the source of stigros.com the code below is what I (and the browser) see's. <link href="styles/main.css" rel="stylesheet" type="text/css" /> <table width="100%" border="0" height="80" cellpadding="4" bgcolor="#000000" > <tr> <td width="81%" height="76" valign="top"><p><span class="stigrosheadfont"><strong>www.StigRos.com</strong></span><strong><span class="headnocrap"><br /> ( No Crap - Just Quality Movie & Music Downloads )</span></span><br /> <a href="http://stigros.com" class="headerlinkcolor">Home</a> | <a href="register.php" class="headerlinkcolor">Register</a> | <a href="#" class="headerlinkcolor">Contact us</a></strong></td> <td width="19%" valign="top"><div align="center"> <div align="center"><span class="stigrosheadfont"><strong>Disclaimer</strong></span></div> <div align="center"> <div style="padding:5px; margin:auto; background-color:#000"<b>1 visitors online</div> February 26, 2011</div></td> </tr> </table> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Stigros.com</title> <link href="styles/main.css" rel="stylesheet" type="text/css" /> </head> <body> <html> <style type="text/css"> #form1 strong { color: #F00; } body { margin-top: 0px; } </style> <body> <form id="form1" name="form1" method="post" action="index.php"> <div align="center"> <p><strong></strong><br /> <span class="blacktext">Your Name:<br /> <input name="username" class="blacktext" type="text" id="username" size="36" maxlength="32" value="" /> <br /> <br /> Your Email: <br /> <input name="email" class="blacktext" type="text" id="email" size="36" maxlength="32" value="" /> <br /> <br /> Your Message: <br /> <textarea name="msg" class="blacktext" id="msg" cols="36" rows="5"></textarea> <br> <br /> Human Check: <input name="humancheck" type="text" id="humancheck" value="Please remove all of this text" size="38" maxlength="32" /> <br /> <br /> <input name="button" type="submit" class="blacktext" id="button" value="Send Now" /> </div> Several things about this are wrong any of which 'might' cause the issue. So, let's look at getting the generated html correct first and then if the problem still exist we can go from there knowing that is not the problem. Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1180101 Share on other sites More sharing options...
finestice Posted February 27, 2011 Author Share Posted February 27, 2011 ummmm im dont think that would actually stop the search.php from not working...its like it kills the script after it gets to 'no search results found' any idea if there is anything in the include file that would stop it...because if i remove it...it works!!!! Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1180358 Share on other sites More sharing options...
swharrell Posted February 28, 2011 Share Posted February 28, 2011 Do you have a link to the actual search.php? I would like to see it's output. Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1180777 Share on other sites More sharing options...
MatthewJ Posted March 3, 2011 Share Posted March 3, 2011 You should back up some posts to where a few different people told you what the actual problem was. You didn't even acknowledge the two posts that would probably have you working? Quote Link to comment https://forums.phpfreaks.com/topic/228835-include-file-not-working/#findComment-1182365 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.