|
Using cookies with php is fairly simple to get started with.
<?php
//setting a cookie
$country = "New Zealand";
$expiry_period = time() + (86400 * 7)); // 86400 = 1 day
setcookie('country',$country,$expiry_period);
?>
<?php
//getting a cookie
$country_value = $_COOKIE['country'];
?>
|
|
|
Sending an email is very simple with php using the function mail()
<?php
$to = "nobody@example.com";
$subject = "Hello email world!";
$body = "This is my emails body?";
$headers = "From: somebody@example.com";
if (mail($to, $subject, $body,$headers)) {
echo("Message sent!");
} else {
echo("Message failed");
}
?>
|
|
Its very easy to get the visitors IP address with php
<?php
$visitors_ip_address = $_SERVER['REMOTE_ADDR'];
?>
|
|
Getting the current page url with php is pretty straight forward. You need to check if the prefix is http or https, then rebuild it with the server variables as shown below.
<?
// check for http or https
if(!empty($_SERVER['HTTPS']))
{
$current_url = "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] ;
} else {
$current_url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
?>
|
|
If you need to remove html tags from a text string it is very simple to do with the function strip_tags().
<?
$str = "<h1>Rocket boots rule!</h1>";
$str = strip_tags($string);
?>
If there are some tags we dont want to remove, strip_tags has an additional parameter which allows us to specify tags to keep
<?
$str = "<h1><i>Rocket boots rule!</i></h1>";
// This will strip all tags except the <i> tags
$str = strip_tags($string,"<i>");
?>
|
|
|
|
|
<< Start < Prev 1 2 Next > End >>
|
|
Page 1 of 2 |