In todays post I’m going to share a simple plugwall script. The script is a simple banner management system that allows website owners to display a set of banners on their site’s splash pages or other pages to attract visitors and encourage them to return. It consists of two main parts: a form for submitting banners and URLs, and a section for displaying the banners on the site.
//Create a file called index.php paste this code in
<?php
// Check if the form has been submitted
if (isset($_POST['submit'])) {
// Get the banner and URL from the form
$banner = $_POST['banner'];
$url = $_POST['url'];
// Validate the banner and URL
if (!empty($banner) && !empty($url)) {
// Write the banner and URL to a flat file
$file = fopen("banners.txt", "a");
fwrite($file, $banner . "," . $url . "\n");
fclose($file);
// Display a success message
echo "Banner and URL submitted successfully!";
} else {
// Display an error message
echo "Please enter both a banner and a URL.";
}
}
?>
<!-- Form for submitting a banner and URL -->
<form method="post">
<label for="banner">Banner:</label><br>
<input type="text" name="banner"><br>
<label for="url">URL:</label><br>
<input type="text" name="url"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
<!-- Display the banners -->
<?php
// Read the banners from the flat file
$file = fopen("banners.txt", "r");
while (!feof($file)) {
$line = fgets($file);
$parts = explode(",", $line);
$banner = $parts[0];
$url = $parts[1];
if (!empty($banner) && !empty($url)) {
echo "<a href='$url'><img src='$banner'></a>";
}
}
fclose($file);
?>
//Create a file called banners.txt also this file stores the submitted banners
Wanna see this script in action try this link
The script begins by checking whether the form has been submitted. If the submit button has been clicked, it retrieves the banner and URL from the form and validates them. If both fields are filled out, the script writes the banner and URL to a flat file called “banners.txt”. If there was an error, the script displays an error message, and if the submission was successful, it displays a success message.
The form itself is straightforward, with two input fields for the banner and URL, respectively, and a submit button. When the user fills out the form and clicks the submit button, the script takes over and processes the data.
The second part of the script reads the banners from the “banners.txt” file and displays them on the site. It opens the file, reads each line, and splits it into two parts: the banner URL and the link URL. If both are present, the script displays the banner image with a link to the URL. This creates a clickable banner that takes the user to the specified destination.
The banners are displayed in a loop, so every banner that has been added to the “banners.txt” file will be displayed on the site. This makes it easy for site owners to add and remove banners as needed, and to experiment with different designs and messages to see what works best.
One use case for this script would be on a splash page or welcome page for a website. When a new user arrives on the site, they could be presented with a set of banners that encourage them to explore the site further or to sign up for a newsletter or other service. Over time, as the user returns to the site, the banners could be updated to reflect new content, promotions, or features, giving the user a reason to keep coming back.
In conclusion, this banner management system is a simple but effective way to add and manage banners on a website. By allowing site owners to easily add and remove banners, and by displaying them in a prominent location, it can help attract and retain visitors, encouraging them to return to the site and engage with its content.