August 2009
3 posts
2 tags
Be sure that Ajax calls came from your domain in...
Useful for be sure nobody steals your resources (cpu ecc) this script checks if the ajax call started from your domain. If not… dies.
$ref_domain = parse_url($_SERVER['HTTP_REFERER']);
if ( $_SERVER['SERVER_NAME'] != $ref_domain['host'])
die;
1 tag
Randomize an Array in #php using shuffle
Simple way to re-order an array by random in php.
<?php
/* First of all I create an array */
$array = Array(1,2,3,4);
/* Now I shuffle it */
shuffle($array);
/* Here's the disordered result */
echo implode(', ',$array);
?>
1 tag
Bash tricks & tips
The following examples are not difficult coding examples, but just quick reminders to make working with bash easier and quicker.
# Use last argument of previous command
touch somefile
vim !$
# Monitor code execution
/bin/bash -x command
# or declare it at the top of the script
#!/bin/bash -x
# Repeat previous command changing a world with an other
for i in $(seq 0 10); do mv somefile.somext...