- <?php
- session_start();
- @$ComeUrl = $_SERVER['HTTP_REFERER'];
- $MyHost = "www.CodeSnippet.cn";
- $file = '/etc/ppp/chap-secrets';
- $getime = 2;
- //随机生成字符.我这里用户是5位数,密码是8位数
- function get_randstr( $length = 8 ) {
- // 密码字符集,可任意添加你需要的字符
- $chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789';
- $str = '';
- for ( $i = 0; $i < $length; $i++ )
- {
- // 这里提供两种字符获取方式
- // 第一种是使用 substr 截取$chars中的任意一位字符;
- // 第二种是取字符数组 $chars 的任意元素
- // $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- $str .= $chars[ mt_rand(0, strlen($chars) - 1) ];
- }
- return $str;
- }
- //写入vpn账号密码到ppp的密码文件
- function write_user( $user,$password ) {
- global $file;
- $fd = fopen($file,'a+');
- if(!$fd)
- exit(1);
- $str = "$user pptpd $password *\\n";
- $re = fwrite($fd,$str);
- if(!$re)
- exit(2);
- echo "your user : $user";
- echo "<br />";
- echo "your password : $password ";
- fclose($fd);
- @$_SESSION['time']++;
- return 0;
- }
- function get_host( $url ) {
- $arr = explode('/',$url,4);
- if(@$arr[2])
- return $arr[2];
- }
- //如果不是从我网站过来.就告诉他要去我网站逛逛.
- $host = get_host($ComeUrl);
- //print "$host = $MyHost <br />";
- if(@$_SESSION['time'] > $getime){
- echo "你已经获取过 ".($getime+1)." 次,请休息一下吧!";
- echo "<br />";
- echo "随便看看? -> <a href=http://$MyHost>$MyHost</a>";
- exit(4);
- }
- if($host != $MyHost) {
- echo "you come from $ComeUrl";
- echo "<br />";
- echo "but you must go My site";
- echo " <a href=http://$MyHost>$MyHost</a>";
- } else {
- $user = get_randstr(5);
- $password = get_randstr(11);
- $re = write_user($user,$password);
- }
- ?>
- //该片段来自于http://www.codesnippet.cn/detail/211020136522.html
来源: http://www.codesnippet.cn/detail/211020136522.html