携帯向けウェブサイト
id:Bayside:20050613:p1 で作った CGI ですが、その後 Vodafone -> SoftBank になったので、その対応をしました。
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char** argv) { char *agent = getenv("HTTP_USER_AGENT"); // エージェント不明 if (agent == NULL) { printf("Location: ./index.html\n\n"); } else { // 携帯(imode) if (strstr(agent, "DoCoMo") != NULL) { printf("Location: ./i/index.html\n\n"); // 携帯(vodafone) } else if (strstr(agent, "J-PHONE") != NULL || strstr(agent, "Vodafone") != NULL || strstr(agent, "SoftBank") != NULL) { printf("Location: ./v/index.html\n\n"); // 携帯(ezweb) } else if (strstr(agent, "UP.Browser") != NULL) { printf("Location: ./e/index.html\n\n"); // PC } else { printf("Location: ./index.html\n\n"); } } return 0; }
だいぶ昔に作ったまま放置していました・・。