Skip to content

Instantly share code, notes, and snippets.

@keiya
Created December 4, 2011 10:09
Show Gist options
  • Select an option

  • Save keiya/1429789 to your computer and use it in GitHub Desktop.

Select an option

Save keiya/1429789 to your computer and use it in GitHub Desktop.
cdDns (redirect as dynamic dns)
<?php
// specify serverside uri
$cddns_server = "http://www.example.com/cddns/server.php";
// specify alias name of ip address. (like a A record host name)
$alias = 'keiyacorg';
// same as server
$password = 'ponponpain';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_URL,"$cddns_server?$alias");
curl_setopt($ch, CURLOPT_POSTFIELDS, "pass=$password");
curl_exec($ch);
curl_close($ch);
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
keiyacorg 59.106.178.118
<?php
$password = 'ponponpain';
$record_file = 'record.csv';
$key = $_SERVER['QUERY_STRING'];
$modifi_r = $_SERVER['REMOTE_ADDR'];
$modified_record = array();
$exists = FALSE;
if ($_POST['pass'] == $password && $_SERVER['REQUEST_METHOD'] == 'POST') {
if (($FH = fopen($record_file,'r+')) !== FALSE) {
while (($record = fgetcsv($FH,0,"\t")) !== FALSE) {
$alias = $record[0];
$redirect = $record[1];
if ($alias == $key) {
$redirect = $modifi_r;
$exists = TRUE;
}
$modified_record[] = array($alias,$redirect);
}
}
if ($exists == FALSE) {
$modified_record[] = array($key,$modifi_r);
}
rewind($FH);
foreach ($modified_record as $fields) {
if (flock($FH,LOCK_EX)) {
fputcsv($FH,$fields,"\t");
}
}
}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (($FH = fopen($record_file,'r')) !== FALSE) {
while (($record = fgetcsv($FH,0,"\t")) !== FALSE) {
$alias = $record[0];
$redirect = $record[1];
if ($alias == $key) {
header("Location:http://$redirect/");
}
}
}
}
fclose($FH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment