cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div style="width:900px; text-align:left; margin: 0px auto 0px auto; padding:20px;">

<span class="navpart">PHP Includes</span>

<br />

<div class="left">

Hypertext Preprocessor is executed server side. PHP variables start with &dollar;. The function sintax and comparison symbols are very similar to Java Script. In PHP . can be used to add multiple variables and data to strings.

<br /><br />

<table style="float:right; margin:0px 0px 10px 20px;"><tr>

<td>
&lt;?php echo
<br />
&lt;&lt;&lt;INC1
<br />
1&lt;br /&gt;
<br />
2&lt;br /&gt;
<br />
3&lt;br /&gt;
<br />
INC1;
<br />
?&gt; &nbsp; 
</td>

<td style="width:20px;">&nbsp;</td>

<td>
<?php echo 
<<<INC1
1<br /> 
2<br /> 
3<br /> 
INC1;
?> 
</td>

<td style="width:20px;">&nbsp;</td>

<td>
&lt;?php echo
<br />
&lt;&lt;&lt;INC2
<br />
A&lt;br /&gt;
<br />
B&lt;br /&gt;
<br />
C&lt;br /&gt;
<br />
INC2;
<br />
?&gt; &nbsp; 
</td>

<td style="width:30px;">&nbsp;</td>

<td>
<?php echo 
<<<INC2
A<br /> 
B<br /> 
C<br /> 
INC2;
?> 
</td>

</tr></table>

<span class="bolet">Write code/content:</span> 

&nbsp; 

&lt;?php echo "..." ?&gt; 

&nbsp; 

<?php echo "..." ?> 

<br />

<span class="bolet">Quotes inside echo:</span> 

&nbsp; \" 

&nbsp; 

&lt;?php echo "This is a \"quoted\" word." ?&gt;

&nbsp;

<?php echo "This is a \"quoted\" word." ?> 

<br />

<span class="bolet">Echo multiple lines:</span> 
All different tag pairs, separate lines, no spaces on the opening &amp; closing tags.

<br />

<span class="bolet">Insert code into html:</span> &nbsp;

&lt;?php include("codefile.php"); ?&gt;

<br />

<span class="bolet">Page redirect:</span> &nbsp;

&lt;?php header('Location: index.php'); ?&gt;

<br />

<span class="bolet">URL variable values:</span>

&nbsp;

Assign value: 

&nbsp;

index.php?page=1

&nbsp;

Retrieve value:

&nbsp;

&lt;?php $variable = $_GET["page"]; ?&gt;

<br />

<span class="bolet">Random number:</span> &nbsp; 

&lt;?php $ranum = mt_rand(1,10); echo $ranum; ?&gt; 

&nbsp; <?php $ranum = mt_rand(1,10); echo $ranum; ?>

<br /><br />

<span class="bolet">Case switch:</span> Break makes the code stop when it reaches a condition it meets.

<br />

&lt;?php 

switch ($variable) {

&nbsp;

case "value1": echo "code here"; break;

&nbsp;

case "value2": include("page1.php"); break; 

&nbsp;

default: header('Location: page2.php'); } 

?&gt;

<br />

<?php $testvariable = $_GET["testvariable"];
switch ($testvariable) { 
case "value1": echo "testvariable is set to value1"; break; 
case "value2": echo "testvariable is set to value2"; break;
default: echo "testvariable is not set"; } ?> 

<br />

<span class="itlet">

&lt;a href="code9.php?testvariable=value1"&gt;Set to value1&lt;/a&gt; | 
&nbsp;
&lt;a href="code9.php?testvariable=value2"&gt;Set to value2&lt;/a&gt; | 
&nbsp;
&lt;a href="code9.php"&gt;Set to null&lt;/a&gt;

&nbsp;

&lt;?php $variable = $_GET["testvariable"];
&nbsp;
switch ($testvariable) { 
&nbsp;
case "value1": echo "testvariable is set to value1"; break; 
&nbsp;
case "value2": echo "testvariable is set to value2"; break;
&nbsp;
default: echo "testvariable is not set"; } ?&gt; 

</span>

<br /><br />

<span class="bolet">Create a cookie:</span> Expiration: 3600 = 1 hour

&nbsp;

&lt;?php setcookie("name", "value", time()+3600); ?&gt;

<br /><br />

<span class="bolet">Set cookie via link:</span>  

Make a php file and put only this code in it. 
It will set the cookie and redirect the page. 
The cookie will save the current path and work only on that folder.

<br />

&lt;?php

setcookie("name", "value", time()+7200);

&nbsp;

header('Location: page.php');

?&gt;

<br /><br />

<span class="bolet">Set cookie for all subfolders:</span> 

&nbsp;

&lt;?php

setcookie("name", "value", time()+7200, "/");

&nbsp;

header('Location: page.php');

?&gt;

<br /><br />

<span class="bolet">Insert code based on cookie value:</span>

&nbsp;

&lt;?php 

if ($_COOKIE["name"] == "value") { code here }

&nbsp;

else { code here }

?&gt;

<br /><br />

<?php $cookievar = ($_COOKIE["testcookie"]);

if ($cookievar=="testcookie is set") { echo $cookievar; }

else { echo "testcookie is not set"; } ?> 

<span class="bolet">Set:</span> &nbsp;

&lt;?php setcookie("testcookie", "testcookie is set", time()+7200, "/"); 

header('Location:http://azurelight.net'); ?&gt;

<br /><br />

<span class="bolet">Delete:</span> (empty value and past date) &nbsp; 

&lt;?php setcookie("testcookie", "", time()-7200, "/"); 

header('Location:http://azurelight.net'); ?&gt;

<br /><br />

<span class="bolet">Changing layout with php and cookies:</span> 

Put the header and footer of each layout in separate php files. 

For each layout, make another php file with only this code, changing the version number, and to switch layouts, link to those files.

<br /><br />

&lt;?php setcookie("layout", "version1", time()+87000, "/"); header('Location:'.$_SERVER['HTTP_REFERER']); ?&gt;

<br /><br />

Place php includes on the top and bottom of each content page.

The header and footer files have a case switch code linking to the layout files.

<br /><br />

&nbsp;
&lt;?php include("head.php"); ?&gt; 
&nbsp; 
Page Content 
&nbsp; 
&lt;?php include("foot.php"); ?&gt;

<br />

&lt;?php &nbsp; $layout = ($_COOKIE["layout"]);
&nbsp;
switch ($layout) {
&nbsp;
case "version1": include("v1top.php"); break;
&nbsp;
case "version2": include("v2top.php"); break;
&nbsp;
default: include("v1top.php"); } &nbsp; ?&gt;

<br />

&lt;?php &nbsp; $layout = ($_COOKIE["layout"]);
&nbsp;
switch ($layout) {
&nbsp;
case "version1": include("v1end.php"); break;
&nbsp;
case "version2": include("v2end.php"); break;
&nbsp;
default: include("v1end.php"); } ?&gt;

<br /><br />

<span class="bolet" id="shpar">Showing and hiding page sections:</span> 

<?php $part1 = "none"; $part2 = "none"; $part3 = "none";

$part = $_GET["part"]; switch ($part) {

case "1": $part1 = "block"; break;

case "2": $part2 = "block"; break;

case "3": $part3 = "block"; break;

default: $part1 = "block"; break; } ?> 

<br />

&lt;?php 
&nbsp;
$part1 = "none"; 
&nbsp;
$part2 = "none"; 
&nbsp;
$part3 = "none";
&nbsp;
$part = $_GET["part"]; switch ($part) {
&nbsp;
case "1": $part1 = "block"; break;
&nbsp;
case "2": $part2 = "block"; break;
&nbsp;
case "3": $part3 = "block"; break;
&nbsp;
default: $part1 = "block"; break; } 
&nbsp;
?&gt; 
<br />
&lt;a href="?part=1"&gt;Part 1&lt;/a&gt; | &lt;a href="?part=2"&gt;Part 2&lt;/a&gt; | &lt;a href="?part=3"&gt;Part 3&lt;/a&gt; 
<br />
&lt;div style="display:&lt;?php echo $part1; ?&gt;;"&gt;Part 1&lt;/div&gt;
&nbsp;
&lt;div style="display:&lt;?php echo $part2; ?&gt;;"&gt;Part 2&lt;/div&gt;
&nbsp;
&lt;div style="display:&lt;?php echo $part3; ?&gt;;"&gt;Part 3&lt;/div&gt;

<br /><br />

<div class="showbor" style="display:inline-block; float:left; margin:0px 20px 10px 0px; text-align:left; padding:10px;">

date('m/d/Y') &nbsp; (full date) &nbsp; <?php echo date('m/d/Y'); ?>

<br />

date("d") &nbsp; (days of the month) &nbsp; <?php echo date("d"); ?>

<br />

date("l") &nbsp; (days of the week) &nbsp; <?php echo date("l"); ?>

<br />

date("N") &nbsp; (days of the week numbers) &nbsp; <?php echo date("N"); ?>

<br />

date("F") &nbsp; (months) &nbsp; <?php echo date("F"); ?>

<br />

date("Y") &nbsp; (full year) &nbsp; <?php echo date("Y"); ?>

</div>

<span class="bolet">Dates:</span>

Changing greeting:  

<?php $today = date('m/d');

if ($today == "11/24") { $greet = "Happy Thanksgiving!"; } 

if ($today == "01/01") { $greet = "Happy New Year!"; } 

if ($today == "02/14") { $greet = "Happy Chocolate Day!"; } 

if ($today == "05/04") { $greet = "May the 4th be with you!"; } 

if ($today == "05/05") { $greet = "Revenge of the 5th!"; } 

if ($today == "07/04") { $greet = "Happy 4th of July!"; } 

if ($today == "10/31") { $greet = "Happy Halloween!"; } 

if ($today == "12/25") { $greet = "Merry Christmas!"; } 

else $greet = "Dtb, have a good day!"; 

echo $greet; ?>

<br />

&lt;?php $today = date('m/d');

if ($today == "12/25") { $greet = "Merry Christmas!"; } 

if ($today == "01/01") { $greet = "Happy New Year!"; } 

else $greet = "Dtb, have a good day!"; 

echo $greet; ?&gt;

<br /><br />

Progress Bar: 5/15 &nbsp; 

<?php $totalwidth = 200; $theparts = 5/15; $wipro = $totalwidth * $theparts; $wipro = round($wipro); ?>

<br />

&lt;?php $totalwidth = <span class="bolet">200</span>; $theparts = <span class="bolet">5/15</span>; $wipro = $totalwidth * $theparts; $wipro = round($wipro); ?&gt;
&lt;div style="background-color:#ffffff; border:1px solid #222222; height:15px; margin:0px auto 0px auto; width:&lt;?php echo $totalwidth ?&gt;px;"&gt; 
&lt;div style="background-color:#0090ff; border:0px none; height:15px; width:&lt;?php echo $wipro; ?&gt;px;"&gt;&lt;/div&gt;&lt;/div&gt; 

<br /><br />

Days progress bar: <?php echo $daycount; ?> <?php echo $dayword; ?> left &nbsp;

<br />

&lt;?php $ttlwidth = <span class="bolet">200</span>;
$startdate = date_create('<span class="bolet">3/7/2015</span>');
$eventdate = date_create('<span class="bolet">2/28/2025</span>');
$timecount = date_diff($startdate, $eventdate);
$datetoday = date('m/d/Y');
$timetoday = date_create($datetoday);
$timewait = date_diff($startdate, $timetoday);
$timeleft = $timewait-&gt;format('%a') / $timecount-&gt;format('%a'); 
$daywidth = $ttlwidth * $timeleft;
$daywidth = round($daywidth); 
$daycount = date_diff($timetoday, $eventdate);
$daycount = $daycount-&gt;format('%a');
$dayword = "days";
if ($daycount == 1) { $dayword = "day"; } 
if ($eventdate &lt; $timetoday) { $daycount = 0; $daywidth = $ttlwidth; } ?&gt;

Days progress bar: &lt;?php echo $daycount; ?&gt; &lt;?php echo $dayword; ?&gt; left &lt;br /&gt;

&lt;div style="background-color:#ffffff; border:1px solid #222222; margin:0px auto 0px auto; height:15px; width:&lt;?php echo $ttlwidth ?&gt;px;"&gt;
&lt;div style="background-color:#0090ff; border:0px none; height:15px; width:&lt;?php echo $daywidth; ?&gt;px;"&gt;&lt;/div&gt;&lt;/div&gt;

</div>
<br />
<a href="http://azurelight.net">AzureLight.net</a> | 
<a href="http://mikaristar.deviantart.com">MikariStar.DeviantArt.com</a> | 
<a href="http://artrift.com/Mikari/">ArtRift.com/Mikari/</a> | 
<a href="http://miliazure.wordpress.com">MiliAzure.WordPress.com</a>
</div>
            
          
!
            
              body { padding:0px; margin:0px; font-family:Arial; font-size:14px; line-height:20px; 
color:#393939; background-color:#c2f0ff; text-align:center; }

::-webkit-scrollbar { width: 10px; height:10px; }
::-webkit-scrollbar-track { background-color:#c2f0ff; }
::-webkit-scrollbar-thumb { border-radius: 20px; background-color:#ff9adc; border: 0px none; }

.showbor { border:0px none; border:3px dotted #ff9adc; padding:0px; } 

a { color:#ff71ce; text-decoration:none; }
            
          
!
999px
Loading ..................

Console