Home Backend Development PHP Tutorial CDN a,b,c三种鉴权的PHP代码

CDN a,b,c三种鉴权的PHP代码

Jun 23, 2016 pm 01:26 PM
b

A鉴权方式的代码

//http://DomainName/Filename?auth_key=timestamp-rand-uid-md5hash

//sstring = "URI-Timestamp-rand-uid-PrivateKey" (URI是用户的请求对象相对地址, 如 /Filename)

//HashValue = md5sum(sstring)

function PrivateKeyA(){

                  $time=strtotime("+8 hours");

                  $key="youkey";

                  $domain="http://www.a.com";

                  $filename="/mulu/1.jpg";

                  //$sstring = "URI-Timestamp-rand-uid-PrivateKey"

                  $sstring = $filename."-".$time."-0-0-".$key;

                  $md5=md5($sstring);

                  $auth_key="auth_key=".$time."-0-0-".$md5;

                  $url=$domain.$filename."?".$auth_key;

                  echo $url."\n";

}


B鉴权方式的代码

//http://DomainName/timestamp/md5hash/FileName

//timestamp:用户访问时客户源服务器的时间,作为URL的一部分,同时作为计算 md5hash 的一个因子,格式为: YYYYMMDDHHMM ,有效时间1800s

//md5hash:以timestamp、FileName和预先设定好的 PrivateKey 共同做MD5获得的字符串,即 md5(PrivateKey + timestamp + FileName)

function PrivateKeyB(){

                  $time=date("YmdHi");

                  $key="youkey";

                  $domain="http://www.a.com/";

                  $filename="/mulu/1.jpg";

                  //$sstring = "PrivateKeytimestampFileName"

                  $sstring = $key.$time.$filename;

                  $md5=md5($sstring);

                  $url=$domain.$time."/".$md5.$filename;

                  echo $url."\n";

}


C鉴权方式的代码:

//http://DomainName/{/}/FileName

//md5hash = md5sum()

//time: 用户访问源服务器时间,取 UNIX 时间,以十六进制数字字符表示。

function PrivateKeyC(){

                  $time2=dechex(time());

                  $key="youkey";

                  $domain="http://ww.a.com/";

                  $filename="/mulu/1.jpg";

                  //$sstring=PrivateKeyFileNametime

                  $sstring=$key.$filename.$time2;

                  $md5=md5($sstring);

                  $url=$domain.$md5."/".$time2.$filename;  

                  echo $url."\n";

}


鉴权错误都是返回 403 

Md5计算类错误:

X-Tengine-Error:denied by req auth: invalid md5hash=de7bfdc915ced05e17380a149bd760be

时间类报错:

X-Tengine-Error:denied by req auth: expired timestamp=1439469547


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to install Windows 11 on ASUS b450 motherboard How to install Windows 11 on ASUS b450 motherboard Dec 31, 2023 am 10:10 AM

ASUS b450 is a very excellent motherboard with many users. If you want to install the win11 system on this motherboard, you need to enable tpm2.0 and the secure boot option. Many friends may not know how to enable it. The editor below will Let’s take a look at how to operate it. How to install win11 on ASUS b450: 1. First, we restart the system, use "F2" to enter the bios settings, and then click "Advanced Mode" in the lower right corner to enter. 2. Then enter "Secure Boot" under the "Startup" option 3. Then select "Windows UEFI Mode" to the right of "Operating System Type" 4. After the settings are completed, click "search" in the upper right corner to enter the search. 5. Then search for “PTT” and click

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Download link of the virtual currency website mobile version APP (the top ten recommended in the world) Download link of the virtual currency website mobile version APP (the top ten recommended in the world) Mar 04, 2025 pm 03:48 PM

This article compares and reviews nine mainstream cryptocurrency exchanges in OKX, Binance, Gate.io, Huobi, Kraken, Coinbase, KuCoin, Crypto.com and Bitstamp. The article conducts detailed analysis and comparison of each exchange from multiple dimensions such as technical advantages, security system, product innovation, global layout, compliance progress, fees, user experience, ecosystem, market position, etc., aiming to help users choose the platform that best suits their needs. OKX is famous for its distributed architecture and derivative trading; Binance occupies a leading position with the world's largest trading volume and rich ecosystem; Gate.io focuses on wide currency coverage and low rates; Huobi focuses on localized services and technical strength;

Top 10 virtual cryptocurrency app trading platforms in 2025 Top 10 virtual cryptocurrency app trading platforms in 2025 Mar 07, 2025 pm 06:39 PM

The top ten virtual cryptocurrency App trading platforms in 2025 are: 1. OKX; 2. Binance; 3. Gate.io; 4. Kraken; 5. Coinbase; 6. Huobi; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Gemini. When choosing a platform, you need to consider: 1. Security; 2. Transaction fees; 3. Trading products; 4. User experience; 5. Customer service support.

How many times has Bitcoin experienced a plunge in history? Where to trade? How many times has Bitcoin experienced a plunge in history? Where to trade? Mar 12, 2025 pm 07:06 PM

Bitcoin price has experienced many violent fluctuations in history, and multiple plunges have caused heavy losses to investors. This article will review the many major plunges of Bitcoin since 2011, including the 85% drop caused by hackers in 2011, the plunge caused by the Mt.Gox incident in 2013 and 2014, as well as the multiple sharp drops caused by factors such as the epidemic period from 2017 to 2018, 2020, China's cryptocurrency ban and the Federal Reserve's interest rate hike, as well as the 66% drop caused by the LUNA/UST collapse in 2022, and even the 6.83% plunge in February 2025, with losses of up to US$2.21 billion. Understanding these historical events will help investors better understand the risks of the Bitcoin market and do

Analysis of the most promising virtual currency in 2025 Top 10 potential virtual currency inventory in 2025 Analysis of the most promising virtual currency in 2025 Top 10 potential virtual currency inventory in 2025 Feb 15, 2025 pm 05:51 PM

The virtual currency market is constantly evolving and exciting growth is expected in the coming years. In 2025, some cryptocurrencies are expected to stand out and become the most promising investments in the space. This article analyzes some of the most promising virtual currencies in 2025, covering their unique capabilities, growth potential and possibilities that impact the future. These currencies include Ethereum, Bitcoin, Cardano, Polkadot and Binance Coin, which play a key role in the development of decentralized finance, smart contracts and blockchain technologies. Understanding the potential of these virtual currencies, investors can be prepared to seize the opportunities brought by the virtual currency market in 2025.

The top10 official website registration portal for currency trading platform The top10 official website registration portal for currency trading platform Mar 04, 2025 pm 09:00 PM

Currency trading is currently a popular investment method, and choosing the right platform is crucial. This article lists the top 10 most recognized currency trading platforms in the industry, providing investors with a comprehensive reference guide. These platforms are known for their superior security, convenient trading capabilities and a wide range of cryptocurrency options. This article highlights the key features of each platform to help investors make informed decisions and choose the platform that best suits their needs and investment strategies.

Recommended digital virtual currency exchanges in 2025. Top ten exchanges in digital currency apps Recommended digital virtual currency exchanges in 2025. Top ten exchanges in digital currency apps Mar 27, 2025 pm 06:21 PM

2025 Newbie currency trading exchange TOP10 recommendations: OKX: Simple operation, powerful intelligent order follow-up function; Binance: The most comprehensive currency, the best liquidity; Gate.io: The first choice for altcoin investment; Bybit (contract); KuCoin (small currency); Bitget (sub-coin); MEXC (innovation currency); HTX (old brand); BitMart (simple); CoinEx (low fee). Newbie suggestions: Priority is given to the top platforms, starting with spot trading, pay attention to enabling security verification, and accumulate experience by testing small amounts of water.

See all articles