Jump to content

[SOLVED] Include Problems


killfall

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?
// 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>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 {

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.