Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing php through html with includes 2

Status
Not open for further replies.

dmacster

Technical User
Jan 28, 2005
670
US
That's the best title I can think of for this. I've a client that has a bunch of html pages already created, and wants to add some banner type ads. I've added the htaccess file to the server and it will parse out the php in the file(s) with html extensions, but it won't use them as includes.

Hope that makes sense.

This works

As well as the same file named as

But when I try to use an include for the banner.php file, something comes up (as viewed through source), but the image doesn't really appear.

See that part here


Can someone point me to a reason for this. The entire script is very simple
Code:
<?php

$random = array(
  array('image' => 'timeshare/banner/1.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => 'timeshare/banner/2.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => 'timeshare/banner/3.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => 'timeshare/banner/4.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => 'timeshare/banner/5.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => 'timeshare/banner/6.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
);

$current = rand(0, count($random) - 1);
print "<a href=\"" . $random[$current]['url'] . "\"><img src=\"" . $random[$current]['image'] . "\" alt=\"\" /></a>\n";

?>

Thanks,
Donna
 
Can we see how you are including your PHP script into the HTML files?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Sure - it's just a page with two single cell tables (that's what the client will use to hold info)

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<p>&nbsp;</p>
<table width="660" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php include "[URL unfurl="true"]http://capegazette.com/timeshareAds/banner.php"[/URL] ?></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="300" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php include "[URL unfurl="true"]http://capegazette.com/timeshareAds/sidebar.php"[/URL] ?></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

Thanks,
Donna
 
2 things jump out at me:

1. your missing a semi colon at the end of your include. yes it the only thing there, but and its likely not the cause of it. But its still recommended to end all your lines with a semi colon ;

2. You are including it with the full http: URL which means it needs to use the url wrappers to open the file. Which if the allow_url_fopen, and allow_url_include directives are not enabled, then it won't include the files.


Since your included files seem to be in the same location as your html files that call them, why not use regular system paths:

include 'banner.php';


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Well, actually the html files will be in multiple places on their end - root level and subdirectories. Even so, I tried as suggested
Code:
<table width="660" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php include 'timeshareAds/banner.php'; ?></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="300" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php include 'timeshareAds/sidebar.php'; ?></td>
  </tr>
</table>

And still only a partial output.

Definitely missed that semicolon somehow. Other thoughts?

Thanks,
Donna
 
you may find using the heredoc syntax easier for embedding html tags within echo statements

Code:
print <<<HTML
	<a href="{$random[$current]['url']}">
	<img src="{$random[$current]['image']}" alt="" />
	</a>

HTML;

the issue as I see it is that you are not returning the value of the url etc relative to the docroot. for example the source code of the html that it produced will look for the banner in rather than
two solutions spring to mind. the first is to code absolute urls in your array.

Code:
<?php
$baseURL = "[URL unfurl="true"]http://capegazette.com/timeshareAds/";[/URL]
$random = array(
  array('image' => $baseURL. 'timeshare/banner/1.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => $baseURL. 'timeshare/banner/2.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => $baseURL. 'timeshare/banner/3.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => $baseURL. 'timeshare/banner/4.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => $baseURL. 'timeshare/banner/5.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => $baseURL. 'timeshare/banner/6.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
);
$current = rand (0, count($random) -1 );
print <<<HTML
	<a href="{$random[$current]['url']}">
		<img src="{$random[$current]['image']}" alt="" />
	</a>

HTML;
?>

the second is to set up an alias in a .htaccess file. create an alias for banner, for example. for example

Code:
Alias /banner /timeshareAds/timeshare/banner

and
PHP:
<?php

$random = array(
  array('image' => '/banner/1.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => '/banner/2.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => '/banner/3.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => '/banner/4.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => '/banner/5.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
  array('image' => '/banner/6.jpg', 'url' => '[URL unfurl="true"]http://google.com/'),[/URL]
);
$current = rand (0, count($random) -1 );
print <<<HTML
	<a href="{$random[$current]['url']}">
		<img src="{$random[$current]['image']}" alt="" />
	</a>

HTML;
?>

other alternatives might include mod_rewrite or using AliasMatch instead of Alias. any of these might work but it is always better to know where your assets are relative to your script, in my opinion.
 
A bit trivial, but do other PHP scripts run? It could be that PHP is not correctly configured in your web server. Just try a PHP page containing
Code:
<?php phpinfo() ?>
and look at it through the browser. If you see that one line in the browser, your web server needs to be configured. If you see a long list of settings, PHP is working and the page tells you what works and what is disabled.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
DonQuichote

Donna gives a url to a php script above that works fine. so i suspect that php problems can be ruled out.
 
Thanks, all. Vacunita for the semicolon, jpadie for the baseURL - works well now.

Donna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top