コード例 #1
0
ファイル: code.php プロジェクト: lilili001/think
<?php

//require dirname(__FILE__).'/includes/common.php';
//echo dechex(mt_rand(0, 15)); //随机数0-15可以创建16进制 dechex(mt_rand)
//获取四位随机码
validateCode();
function validateCode()
{
    session_start();
    for ($i = 0; $i < 4; $i++) {
        $randomNum = dechex(mt_rand(0, 15));
        $_nmsg .= $randomNum;
    }
    $_SESSION['code'] = $_nmsg;
    //echo $_SESSION['code'];
    //echo $_nmsg; //变量不可以跨页面 但是session可以  利用超级全局变量
    $_width = 75;
    $_height = 25;
    $_img = imagecreatetruecolor($_width, $_height);
    //白色
    $_white = imagecolorallocate($_img, 255, 255, 255);
    //填充
    imagefill($_img, 0, 0, $_white);
    //黑色
    $_black = imagecolorallocate($_img, 0, 0, 0);
    //画一个黑色的边框
    imagerectangle($_img, 0, 0, $_width - 1, $_height - 1, $_black);
    //随机线条
    for ($i = 0; $i < 6; $i++) {
        $_randomColor = imagecolorallocate($_img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
        imageline($_img, mt_rand(0, $_width), mt_rand(0, $_height), mt_rand(0, $_width), mt_rand(0, $_height), $_randomColor);
コード例 #2
0
ファイル: index.php プロジェクト: stevenmirabito/shorten
function validateCode($string)
{
    if (preg_match("/^[\\w]+\$/", $string)) {
        return true;
    } else {
        return false;
    }
}
function startsWith($haystack, $needle)
{
    return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}
if ($enabled) {
    $inurl = $_SERVER["REQUEST_URI"];
    $code = substr($inurl, strpos($inurl, "?") + 1);
    if (validateCode($code)) {
        $url = $owncloud_url . "/index.php/apps/shorten/code.php?code=" . $code;
        ini_set('user_agent', 'ownCloud Downloader;');
        $headers = get_headers($url);
        foreach ($headers as $h) {
            if (startsWith($h, "Location:")) {
                header($h);
                exit;
            }
        }
        foreach ($headers as $h) {
            header($h);
        }
        $f = fopen($url, 'r');
        while (!feof($f)) {
            if ($f) {