php 跨站点脚本编制_一个脚本中的四个季节:使用PHP创建季节性站点主题

php 跨站点脚本编制

Having just officially passed into spring here, it feels appropriate to provide a lesson on creating seasonal themes for web sites. Regularly changing the appearance of a site in tune with the seasons can help keep the site looking fresh and current; to me, there’s something homely and warm about a web page that reflects the changes in hue and tone of the world outside. Of course, that’s true of only half the world, the seasons are reversed between the northern and southern hemispheres: when Canada is locked in the icy depths of winter, my birthplace of New Zealand is enjoying the heights of summer. In addition, the change of season is calculated in different ways in each hemisphere.

在这里正式进入Spring之后,提供有关创建网站季节性主题的课程是适当的。 定期根据季节改变站点的外观可以帮助保持站点的新鲜感和时效性; 对我来说,网页上有种家常便饭,它反映出外界的色调和色调的变化。 当然,只有一半的世界是这样,北半球和南半球之间的季节是相反的:当加拿大被困在冬天冰冷的深处时,我的出生地新西兰正享受着夏季的高峰。 此外,在每个半球以不同的方式计算季节变化。

Whatever system you decide to follow, and whatever season you choose to reflect, you don't want to switch your site theme by hand four times a year. It’s much more efficient to let a script calculate the date and apply the necessary changes to your CSS.

无论您决定采用哪种系统,以及选择反映的季节如何,都不想每年手动四次切换网站主题。 让脚本计算日期并将必要的更改应用于CSS效率更高。

The technology you use to create this script depend on your needs. A server-side technology such as will always work, but it will use the server’s date. That time will always be correct for the server’s location, but will not match the visitor’s experience if they are from the opposite hemisphere. I will cover the JavaScript solution in a later article, but it has its own advantages and downsides.

用于创建此脚本的技术取决于您的需求。 服务器端技术(例如将始终有效,但会使用服务器的日期。 那个时间对于服务器的位置永远是正确的,但是如果访问者来自相反的半球,则与访问者的体验不符。 我将在以后的文章中介绍JavaScript解决方案,但是它有其自身的优点和缺点。

Using PHP, you’ll have to start with the technique I referenced earlier in tricking PHP into believing it is a CSS page. This script will be written in this styles.php page:

使用PHP,您必须从我之前引用的技巧入手,以使PHP相信它是CSS页面 。 该脚本将在以下styles.php页面中编写:

<?php
	header('Content-type: text/css');
	$ss = array('winter','spring','summer','autumn', 'winter');
	$m = intval(date('m'));
	$season = $ss[$m/3];
?>

Very simply: $ss is an array that contains the name of the seasons; $m calculates an integer from the current month. We divide $m by 3 to get the nearest round number, and use that number to get the appropriate season from the $ss array (remember that array slots start from 0). For example, if it were December, the numeric month would be 12; divided by three, the result is 4, which would be the last slot in the array. March will be month three, divided by 3, the result is 1, which would match spring in the array.

非常简单: $ss是一个包含季节名称的数组; $m从当前月份计算一个整数。 我们将$m除以3得到最接近的整数,并使用该数字从$ss数组中获取合适的季节(请记住,数组插槽从0开始)。 例如,如果是12月,则数字月将为12;否则为12。 除以三,结果为4,这将是阵列中的最后一个插槽。 三月将是第三个月,除以3,结果为1,这将与数组中的spring匹配。

While this isn’t perfectly accurate for traditional northern hemisphere calculation of the seasons (more precise vernal equinox PHP scripts are available), it’s entirely acceptable for most sites.

尽管对于传统的北半球季节计算而言,这并不完全准确(可以使用更精确的春分PHP脚本 ),但对于大多数站点而言,这是完全可以接受的。

Once we have a value for $season, we can use it for all kinds of purposes in the styles.php page:

一旦有了$season的值,就可以在styles.php页面中将其用于各种目的:

h1 {
	background: url("images/<?=$season?>.jpg");
}

This will place the appropriate image for the season (summer.jpg, etc) as a background image for the h1 element of all pages that link to styles.php.

这将为该季节放置适当的图像( summer.jpg等),作为链接到styles.php的所有页面的h1元素的背景图像

Taking this a step further, you could add something like the following:

更进一步,您可以添加如下内容:

<?
	if ($season == "spring" || $season == "summer" ) { ?>
body { background: #97a349; }
/* other styles associated with spring and summer */
	<? } else { ?>
body { background: #bebebe; }
/* other styles associated with winter and autumn */
<? } ?>

A thorough theme switch would address site colors for every season separately (cold, bleak whites, greys and light blues for winter, oranges and reds for fall) perhaps including animations (subtle falling snowflakes or leaves in backgrounds, for example).

彻底的主题切换将分别解决每个季节的站点颜色(冬天为冷,暗淡的白色,灰色和淡蓝色,秋天为橙色和红色),可能包括动画(例如,飘落的雪花或背景中的叶子)。

翻译自: https://thenewcode.com/496/Four-Seasons-In-One-Script-Creating-Seasonal-Site-Themes-With-PHP

php 跨站点脚本编制

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值