How to Create Code That Can Be Changed

Problem: I would like to insert 3 image banner/ads in the header of my website (which will show up the same on every page). But about once a month, I’ll need to change the promotions for each of the 3 ads (and of course, the same changes will be made for every page).

Each banner/ad will simply point to a different web page.

Is there a way to set this up so that when I make changes to the code, the effect will take place on every page on my website?

I don’t want to open each web page, and have to edit the code on every single page. It will take too long…

With PHP you can use an include file. The file can be included in multiple web pages. Simily edit the one file and the changes will appear on all pages that include it. You’ll have to learn a little PHP and host your site on a server that supports PHP. There may be other solutions, but this is the one I’d use.

<html>
<body>

<?php include(“header.php”); ?>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>

</body>
</html>

W3C school source

Thank you!

Hi jihanemo,

you can also create a folder called “block” where you can have a different .php files that can be used for common menu, footer, and so on…

This is useful when you want to make a change in particular area.

@jihanemo

In case it’s of use, I put together this little beginner tute on this topic. May help explain it. :slight_smile:

Thank you!

You could even get the included file to change automatically depending on the date:



	$day = date('d');
	switch($day;)
	{
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
		case 11:
		case 12:	include('first_12_days.php');
		break;
		
		case 13:
		case 14:
		case 15:
		case 16:
		case 17:
		case 18:
		case 19:		include('teen_days.php');
		break;
		
		default:	include('last_days.php');
	}


.