PHP Website Maker
Wednesday, July 4, 2012
Redirect webpage to the same page with a message
Redirect webpage to the same page with a message
Processing the form on the same page or is the form action a separate file? If it is a separate file, you can redirect after form processing using the header function and passing in a get variable like so:
Code:
if($form_success){
header('original_page.php?success=true');
}
Here I am checking a made-up variable called $form_success, though it would probably contain a boolean value based on whether the form successfully submitted or not. If it did submit, I am redirecting the user to original_page.php with a GET variable success = true. This can be accessed on your form page (wherever you want the message to display in the HTML) like this:
Code:
if(isset($_GET['success'])){
if($_GET['success'] == 'true'){
echo '<div class="success">THANK YOU. YOUR DATA HAS BEEN SUBMITTED</div>'
}else{
echo '<div class="error">SORRY, PROBLEM SUBMITTING YOUR DATA</div>'
}
}
Tuesday, July 3, 2012
PHP - Simple Ad Rotation Script
PHP - Simple Ad Rotation Script
In this script (very easy script), we setup 3 ads for rotation. First ad, we want it to display 70%, second ad we want to display 20% and the last one we want to display 10%
What to do
1. Random number 1-100
if result = 1-70 (we have opportunity to display ad1, 70%)
if result = 71-90 (we have opportunity to display ad2, 20%)
if result = 91-100 (we have opportunity to display ad3, 10%)
Example
In this script, we use rand(1, 100); to random number between 1 -100 and keep the result in variable named "$result_random" if result = 85 ad2 will be displayed.
Code -
<?php
// random number 1 - 100 $result_random = rand(1, 100);
// if result less than or equal 70, display ad1 (70%)
if($result_random <= 70){
echo "Display ad1";
}
// if result less than or equal 90, display ad2 (20%)
else if($result_random <= 90){
echo "Display ad2";
}
// if result less than or equal 100, display ad3 (10%)
else {
echo "Display ad3";
}
?>
PHP - Get full web page URL from address bar
PHP - Get full web page URL from address bar
Syntax
<?php
$server=$_SERVER['HTTP_HOST'];
echo $server;
$request_url=$_SERVER['REQUEST_URI'];
echo $request_url;
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
?>
Java Script:
This is an example of javascript and php script, click to select all text in text box like infobrainz.com or many other site.
<head>
<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form_name.type");
text_val.focus();
text_val.select();
}
</script>
</head>
PHP Redirection script
PHP Redirection script
Learn how to redirect in this tutorial, you can use header(); function in php or use meta to redirect to a new page you want or redirect to other website. In this scripts, you can use header(); method or use meta to redirect.
Code - PHP Redirection script
// For example, redirecting to www.infobrainz.com
header("location:http://www.phpeasystep.com");
or
echo "<meta http-equiv='refresh' content='0;url=http://www.phpeasystep.com'>";
PHP - Automatic refresh webpage / Set time to redirect
PHP - Automatic refresh webpage / Set time to redirect
When you need your web page automatically refresh in 5 second or any second you want, you can use this meta tag. It's a simple code, put it between tag ... on your web page.
This script is easy but powerful. Many websites use this script to redirect their web page or refresh the same page, for example, my website updates in every 10 minutes and I want to show user my latest content then I put this script to my page and set it refreshs in every 10 minutes.
Code -
<HEAD>
<meta http-equiv='refresh' content='2;url='file_name or URL'>
</HEAD>
// content = time (second).
// file_name = name of file you want to refresh or redirect.
// URL = URL of website that you want to redirect to.
Thursday, June 28, 2012
Popup Form with HTML, CSS, Java Script
Popup Form with HTML, CSS, Java Script
=============================
#lightbox{
visibility:hidden;
position:absolute;
background:blue;
border:2px solid #3c3c3c;
color:white;
z-index:200;
width: 400px;
height:300px;
padding:40px;
}
.dimmer{
background: #000;
position: absolute;
opacity: .5;
top: 0;
z-index:50;
}
Java Script
===========
var opener = document.getElementById("opener");
opener.onclick = function(){
var lightbox = document.getElementById("lightbox"),
dimmer = document.createElement("div");
dimmer.style.width = window.innerWidth + 'px';
dimmer.style.height = window.innerHeight + 'px';
dimmer.className = 'dimmer';
dimmer.onclick = function(){
document.body.removeChild(this);
lightbox.style.visibility = 'hidden';
}
document.body.appendChild(dimmer);
lightbox.style.visibility = 'visible';
lightbox.style.top = window.innerHeight/6 - 20 + 'px';
lightbox.style.left = window.innerWidth/6 - 20 + 'px';
return false;
}
HTML
====
<div id="lightbox">
<form id='contactus' action='' method='post' accept-charset='UTF-8'>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='' maxlength="50" /><br/>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='' maxlength="50" /><br/>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<textarea rows="10" cols="50" name='message' id='message'></textarea>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</form>
</div>
<a href="#" id="opener">Click me</a>
User for testing for HTML/CSS/JS
http://jsfiddle.net/rxGmk/43/
Monday, June 11, 2012
PHP - Automatic Copyright Year
PHP - Automatic Copyright Year
Current year only
© <?php echo date("Y") ?>
With start year
© 2008-<?php echo date("Y") ?>
Start date with error protection
<?php function auto_copyright($year = 'auto'){ ?>
<?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
<?php if(intval($year) == date('Y')){ echo intval($year); } ?>
<?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
<?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
<?php } ?>
Usage:
<?php auto_copyright(); // 2011?>
<?php auto_copyright('2010'); // 2010 - 2011 ?>
Subscribe to:
Posts (Atom)