killfall Posted July 28, 2008 Share Posted July 28, 2008 Im fairly new to Programming and have only been using PHP for a year or so. I have made a website with includes and a SQL database to do all the work. The site consists of one main page with includes based on .php?p=page so the site gets the variable and searches the database for it, then loads the write include and color set. But im having a problem as one of the included page needs to get another variable from the URL so its .php?p=page&guid=guid but the included code is parsed before being included so the variable is missed. And I dont know what to do. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/ Share on other sites More sharing options...
synking Posted July 28, 2008 Share Posted July 28, 2008 I don't know if this will help but try a require on the second include instead. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-601638 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 Well I've tried using that and still no joy. The included code for some reason doesn't pick up any variables from the rest of the document or the URL and just ignores them. I also have the problem of the included pages not using the SQL connection and coming up sayin incorrect username and password. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602556 Share on other sites More sharing options...
jonsjava Posted July 29, 2008 Share Posted July 29, 2008 sounds like you're including the page out of order. Include the page with errors after you include your db connect stuff. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602558 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 I have, The database connect is the first thing in the file. And it also gets the URL variable and sets it as a variable. But when the included file calls it nothing happens. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602566 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 can you show your code Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602587 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 <? // SQL Server Connect $dbhost = 'localhost'; $dbuser = 'kaedoonl_test'; $dbpass = 'cheese'; $dbname = 'kaedoonl_news'; $tbname = 'user'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Database Connect Error'); mysql_select_db($dbname, $conn) or die ($dbname . " Database not found." . $dbuser); // Generate String function func_generate_string() { $auto_string= chr(mt_rand(ord('A'), ord('Z'))); for ($i= 0; $i<8; $i++) { $ltr= mt_rand(1, 3); if ($ltr==1) $auto_password .= chr(mt_rand(ord('A'), ord('Z'))); if ($ltr==2) $auto_password .= chr(mt_rand(ord('a'), ord('z'))); if ($ltr==3) $auto_password .= chr(mt_rand(ord('0'), ord('9'))); } return $auto_string; // Login Scripts if (isset($_COOKIE[kaedolog])) { $cookie = $_COOKIE[kaedolog]; list($user_id, $logcode) = explode(":", $cookie); } else { $user_id = '0'; $logcode = 'logcode'; $cookieval = '$user_id:$logcode'; setcookie("kaedolog", $cookieval, time() + 7200, "", ".kaedo-online.net"); $cookie = $_COOKIE[kaedolog]; } $res= mysql_query("SELECT * FROM user WHERE user_id = $user_id") or die('Could Not Find User, Please <a href="http://www.kaedo-online.net/login.php">Login</a>'); if (mysql_num_rows($res)==1) { while ($row = mysql_fetch_assoc($res)) { $logcode2=$row["logcode"]; $user=$row["user"]; $forename=$row["forename"]; $surname=$row["surname"]; $email=$row["email"]; $status=$row["status"]; } mysql_free_result($res); if ($logcode == $logcode2) { setcookie("kaedolog", $cookie, time() + 7200, "", ".kaedo-online.net"); } } else { echo 'owned'; } } // Get Page Variable if(isset($_GET[p])) { $page_id = $_GET[p] ; $res= mysql_query("SELECT * FROM site WHERE id = '$page_id'") or die('Incorect Page ID'); $row = mysql_fetch_assoc($res); $name=$row["name"]; $color=$row["color"]; $content_id=$row["content"]; $header_include=$row["header"]; mysql_free_result($res); } else { header('Location:http://web.kaedo-online.net/?p=6a992d5529f459a44fee58c733255e86'); } $content = 'http://web.kaedo-online.net/pages/'.$content_id.'.php'; $guid = ($_GET[guid]) ; //Header Content if($header_include == 'y') { $header_content = 'http://web.kaedo-online.net/pages/'.$content_id.'_header.php'; } else { } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Kaedo Online</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .style1 { font-family: Arial, Helvetica, sans-serif; color: #FFFFFF; text-decoration: none; } a:link { text-decoration: none; } a:visited { text-decoration: none; color: #FFFFFF; } a:hover { color: #3399FF; } a:active { text-decoration: none; } .style2 { font-family: Arial, Helvetica, sans-serif; color: #000000; text-decoration: none; } a:link { text-decoration: none; color: #000000; } a:visited { text-decoration: none; color: #000000; } a:hover { color: #3399FF; } a:active { text-decoration: none; } --> </style> <? if(isset($header_content)) { include $header_content ; } else { } ?> </head> <body> <table width="769" border="0" align="center" cellpadding="0" cellspacing="0">  <tr>   <td width="763" align="center" bgcolor="<? echo $color ?>"> <p class="style2"><span class="style1"> <font color="#FFFFFF"><a href="http://web.kaedo-online.net"><font color="#FFFFFF">Home</font></a> - <a href="http://web.kaedo-online.net/?p=<? echo md5(dusk) ?>"><font color="#FFFFFF">DUSK</font></a> - <a href="http://web.kaedo-online.net/?p=<? echo md5(guitar) ?>"><font color="#FFFFFF">Guitars</font></a> - <a href="http://web.kaedo-online.net/?p=<? echo md5(r2d2) ?>"><font color="#FFFFFF">R2-D2</font></a> - <a href="http://web.kaedo-online.net/?p=<? echo md5(podcast) ?>"><font color="#FFFFFF">Podcasts</font></a> - <a href="http://web.kaedo-online.net/?p=<? echo md5(kaedo) ?>"><font color="#FFFFFF">Kaedo</font></a>   </font> </span></td>   <td width="763" bgcolor="<? echo $color ?>"> </td>  </tr>  <tr>   <td colspan="2"><p class="style5"> <? if ($name == 'Index') { echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="800" height="100" id="banner2" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="banner2.swf" /> <param name="loop" value="false" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed src="http://images.kaedo-online.net/banners/banner2.swf" loop="false" quality="high" bgcolor="#ffffff" width="800" height="100" name="banner2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>'; } else { echo '<img src="http://images.kaedo-online.net/banners/banner1.png" alt="Kaedo Banner" width="782" height="113">'; } ?> </p>   </td>  </tr>  <tr>   <td colspan="2" class="style2"> <? // Main Page require $content; echo $guid; include $content; ?> </td>  </tr>  <tr>   <td colspan="2" bgcolor="<? echo $color ?>"> <div align="center">  <table width="800" border="0">   <tr>    <td width="145" align="left"><span class="style1"><a href="http://kaedo-online.net/about.php"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">About Us</font></a></span></td>    <td width="149" align="left"><span class="style1"><a href="http://kaedo-online.net/map.php"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">Site Map</font></a></span></td>    <td width="492"><div align="right"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">Kaedo © 2007-08</font></div></td>   </tr>   <tr>    <td align="left"><span class="style1"><a href="http://www.kaedo-online.net/contact.php"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">Contact Us</font></a></span></td>    <td align="left"><span class="style1"><a href="http://kaedo-online.net/link.php"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">Link to Us</font></a></span></td>    <td align="right"> <p>   <a href="http://validator.w3.org/check?uri=referer"><img     src="http://www.w3.org/Icons/valid-html401-blue"     alt="Valid HTML 4.01 Transitional" height="31" width="88" border="0" style=" float:right; margin-bottom:0px; margin-right:0px; margin-top:0px;"></a>  </p>  </td>   </tr></table> </div></td>  </tr> </table> </body> <?php mysql_close($conn); ?> </html> Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602590 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 echo out $header_content, and see if it is what u expect Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602591 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602593 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 echo out $header_content and see if it contains what it should Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602595 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 well the header content is for if i have any pages that needs stuff put in the header the SQL database tells it that it needs to include the header content. For like javascript and stuff. And on all pages it should say no header content in the database anyway, so It shouldnt make a difference. Â Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602600 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 can u just echo it out and tell us what it says Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602602 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 nothing, its blank Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602607 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 then theres your problem , there is nothing in the include, so it won't include anything Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602616 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 thats not my problem, if you look down near the bottom it says include $content, that content is a .php file which contains <? echo $guid ?> that is set near the top of th code, but nothing comes up Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602619 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2008 Share Posted July 29, 2008 If you are including files through the file system, GET parameters on the end of the file name have no effect (like it states in the include section of the php manual.) You would need to setup the correct $_GET['xxx'] variables before the include() statement if you want them to be available to the included code. Â If you are including files using a URL, then it should work as is. Â Give an example of your include() statement. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602627 Share on other sites More sharing options...
synking Posted July 29, 2008 Share Posted July 29, 2008 if i see right unless the guid is set in some other script guid is empty. what should the guid have. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602629 Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 you are trying to include a URL ? if yes..then it will include the HTML which is displayed by that URL and not the actual PHP code in it.. Â Is this file on the same server as yours ? if yes, try using absolute path and not URL. if no, then it wont allow you to use PHP code. Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602631 Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 if you want to use the HTML of the URL included and pass guid there try this. Â $guid = ($_GET[guid]) ; //Header Content if($header_include == 'y') { Â $header_content = 'http://web.kaedo-online.net/pages/'.$content_id.'_header.php?guid='.$guid; } else { Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602635 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 Well the code in the included file is <? echo $guid ?> And the variable $guid is set in the header as $guid = $_get[guid] But nothing is coming up Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602751 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 I have tried making a test page and am still having the same problem with that. Â The test page (http://web.kaedo-online.net/test.php) Â <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? $guid = 'test'; include 'http://web.kaedo-online.net/pages/r2d2.php' ?> </body> </html> Â Then the included code (http://web.kaedo-online.net/pages/r2d2.php) Â <? echo $guid; ?> Â And the test page comes up blank Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602766 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 that means that on the page u included , the varaible is being set to empty Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602771 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 So why is it doing that, because I set the variable to 'test' just before the include? Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602783 Share on other sites More sharing options...
DeanWhitehouse Posted July 29, 2008 Share Posted July 29, 2008 as i just said,the page you are including , is reseting the var Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602787 Share on other sites More sharing options...
killfall Posted July 29, 2008 Author Share Posted July 29, 2008 So how do I avoid it doing that? Quote Link to comment https://forums.phpfreaks.com/topic/116988-solved-include-problems/#findComment-602790 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.