How to use an array to check strpos in php

This is a really nice example of how to search for an array of words when using StrPos in php function strposa($haystack, $needle, $offset=0) { if(!is_array($needle)) $needle = array($needle); foreach($needle as $query) More »

Session counter using the Google Analytics ga.gs __utma cookie

Sometimes it would be nice to work out if a user is a returning visitor or not, perhaps even to know how many times they have visited. However a visitor count is More »

Getting and setting cookies in an iframe with P3P and PHP

HTTP is a stateless protocol, which means that every request you make to a website is standalone and therefore cannot keep data by itself. But this simplicity is also one of the More »

Monkey bike, chaly and lady dax

A collection of Monkey bikes. There is also an electric bike that was home made. The bikes though are a jincheng bored up to 85cc, with kitaco swinger and kitaco wheels and More »

Parse Web Pages with PHP Simple HTML DOM Parser

Parse Web Pages with PHP Simple HTML DOM Parser via Parse Web Pages with PHP Simple HTML DOM Parser.##   very useful instead of messing around with regex and preg_match ! +2-1 More »

How to use an array to check strpos in php

This is a really nice example of how to search for an array of words when using StrPos in php

function strposa($haystack, $needle, $offset=0) {
    if(!is_array($needle)) $needle = array($needle);
    foreach($needle as $query) {
        if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result
    }
    return false;
}
$string = 'Whis string contains word "cheese" and "tea".';
$array  = array('burger', 'melon', 'cheese', 'milk');
var_dump(strposa($string, $array)); // will return true, since "cheese" has been found

if (strposa($string, $array)) {

// then do something

}

  

MySQL GROUP BY Modifiers the one called rollup

what an amazing SQL option, basically adds a group total to any records that you run, and identified by a null so you dont confuse it with returned data

 

http://dev.mysql.com/doc/refman/5.0/en/group-by-modifiers.html

  

Session counter using the Google Analytics ga.gs __utma cookie

Sometimes it would be nice to work out if a user is a returning visitor or not, perhaps even to know how many times they have visited. However a visitor count is a bit of a pain as someone might look at lots of pages, so why not take advantage of the Google Analytics cookie and take the count from that.

You see the __utma cookie that Google sets contains the session count as the last part. This is how many times a user comes and visits a bunch of pages and then leaves. It is pretty easy to just break that apart and read out the value which is in PHP below.

 

<?php
$utma               = array_key_exists(“__utma”,$_COOKIE) ? $_COOKIE["__utma"] : 0;
$utma_parts  = $utma ? explode(‘.’, $utma) : array();
$ga_visits       = array_key_exists(5, $utma_parts) ? $utma_parts[5] : 0;

echo “<h3>sessions $ga_visits</h3>”;

if( $ga_visits >=2 )
{
echo “Special Offers for people who have been here more than once”;
} else {
echo ‘No Special Offers for first time users’;
}
?>

  

Getting and setting cookies in an iframe with P3P and PHP

HTTP is a stateless protocol, which means that every request you make to a website is standalone and therefore cannot keep data by itself. But this simplicity is also one of the reasons for its widespread adoption in the early ears of the web.

There is, however, a way to keep information between requests in the form of cookies. This way you can have effective session managemet and persistent data.

There are two ways to work with cookies – server side (PHP, ASP etc) and client side (JavaScript). In this MicroTut we are going to take a look at how cookies are created and read in both PHP and JavaScript.

This tutorial gives a nice easy example as how to set this, however if you want it to work in an iframe and also then work on IE 6 etc, then you also need to set a P3P Header. For this I use this in PHP

header(“P3P: policyref=\”http://your_domain_here.com/c/p3p.xml\”, CP=\”CURa ADMa DEVa CONo HISa OUR IND DSP ALL COR\”");

 

 

Micro tutorial to set and retrieve cookies