Jump to content

[SOLVED] dependent includes?


el_bob

Recommended Posts

hi -

 

i've got a page someone else built with an include for another file. the include needed a random banner, both jpeg and swf.

 

so i figured that one out - i've set up an include in that file which calls the proper code randomly from a text file, one line with the embed for the swf and one line with the image (both in their own link tag - a href...)

 

so here's the issue -

 

back on the top level, there's another banner which needs to be dependent on the include inside the include.  they're in 2 completely different places, so tying them into the same file is not an option.

 

i have ABSOLUTELY no idea where to even start on that one.

 

anyone??

Link to comment
https://forums.phpfreaks.com/topic/60578-solved-dependent-includes/
Share on other sites

do you mean something like this?

 

<?PHP
//code before the head of the html
?>
HTML HEAD STUFF
<body>
<?PHP
//php code
include 'xxx.xxx';
//more code
include 'xxx.xxx';
//more code...
?>
</body>
END OF THE FILE

 

if not then can you try and explain more clearly

sorry - i'll try to explain better

 

here's the page hierarchy

 

  • regular page
       

    •        
  • header include.php
           

    •            
  • banner randomizer include.php (getting html source code from text file)
               

       

   

   

[*]more regular page stuff

[*]other regular page banner which needs to be dependent on banner randomizer include.php result

 

 

make more sense?

 

not preticullary, im still stuck with what your saying,

 

you mean a structure like this?

 

index.php (for instance)

|-include 'zzzz.php'

||-include 'yyyy.php'

|-include 'xxxx.php'

||-include 'wwww.php'

 

so you include 2 files, and both those files include more files?

 

i really dont get what you mean, can you post the code?

sorry, i can't.

 

but

 

index.php

|-include 'header.php'

||-include 'get_banner.php'

|||random.txt (contains html to be placed into index.php, seperated by carriage returns)

content

skyscraper dependent on results of index/header/get_banner  (THIS IS THE ONE I NEED)

 

 

 

so i include one file, which includes another file, which feeds info into the index from yet another file.

 

ok, all you need in the index.php file is:

include 'xxxx.php'

inside that you need:

include 'xxxx.php'

then add this inside that:

include 'xxxx.txt'

 

so then the index file will show the txt file along with the other files

 

Index.php:

include 'header.php';

header.php

include 'get_banner.php';

get_banner.php

include 'random.txt';

right - i've already got that

 

but let's say "random.txt" put the following line of code into index.php -

 

<a href="http://www.joeschmoe.com" target"_blank"><img src="banners/joeschmoebanner.jpg" /></a>

 

how do i then make sure that the next banner down gets the message that this is a joeschmoe page and not a fredschmed page, and loads a joeschmoe image accordingly?

 

to cut off a few simple ideas already passed:

 

can't have different pages - bookmark needs to always go back to index.

can't setup a "joeschmoe" tag, cuz the doubly-nested "get_banner.php" won't get the message

ok, i think i fixeded it....

 

in the .txt file, i added an element id (same - banner) and a class (different - numbered 1-whatever for ease)

 

in the index doc, i added a javascript to get the class of banner and write html code base on that

 

NOW

 

since my php is limited to looking at an existing script and twiddling with it once i see what links with what

 

is there code to do this in php?

 

here's the javascript

 

<script language="JavaScript" type="text/javascript">
  var el_banner = document.getElementById("banner");
  	if (el_banner.className=="1") {
	document.write ('<a href="http:\/\/www.joeschmoe.com" target="_blank"><img src="Banners\/joeschmoeTall.jpg" width="160" height="600"><\/a> ');
} else {
	document.write ('<a href="http:\/\/www.fredschmed.com" target="_blank"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0" width="160" height="600" title="fredschmed">')
        document.write ('<param name="movie" value="Banners\/fredschmedTall.swf">')
        document.write ('<param name="quality" value="high">')
        document.write ('<embed src="Banners\/fredschmedtall.swf" quality="high" pluginspage="http:\/\/www.macromedia.com\/go\/getflashplayer" type="application\/x-shockwave-flash" width="160" height="600"><\/embed>')
        document.write ('<\/object><\/a>');
	}
</script>

try this:

 

$chars = array('<a href="http://www.joeschmoe.com" target="_blank"><img src="Banners/joeschmoeTall.jpg" width="160" height="600"></a>', <a href="http:\/\/www.fredschmed.com" target="_blank"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0" width="160" height="600" title="fredschmed">');
$length = 1;
$textstr = "";
for ($i=0; $i<$length; $i++) {
   $textstr .= $chars[rand(0, count($chars)-1)];
}

echo $textstr;

ok, if you are using that code i just gave you, then just change it to:

 

$chars = array('<a href="http://www.joeschmoe.com" target="_blank"><img src="Banners/joeschmoeTall.jpg" width="160" height="600"></a>', <a href="http:\/\/www.fredschmed.com" target="_blank"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0" width="160" height="600" title="fredschmed">');
$length = 1;
$textstr = "";
for ($i=0; $i<$length; $i++) {
   $textstr .= $chars[rand(0, count($chars)-1)];
}

 

and then place this whereever you want it:

 

echo $textstr;

 

if its not that then just tell me

nope, fixed it

 

so i just added the skyscraper code to the txt file using a --/-- delimiter, got the whole line using the carriage return delimiter, exploded the pieces using the --/-- and printed the pieces where i needed them.

 

so the code is

 

$filename = "random.txt";
$file = file($filename);

  srand((double)microtime()*1000000);
  while ($RandomRotator == "") {
  $RandomRotator = ereg_replace("\n","",$file[rand(0,count($file))]);
  }

$pieces = explode("--/--", $RandomRotator);
print $pieces[0];

 

and then later in the page

 

print $pieces[1];

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.