asp/asp.net/php实现301重定向代码
asp教程/asp.net教程/php教程实现301重定向代码,一般我们做301是全用iis,apache来实现,在没有操作服务器的时我们再用脚本来实现,代码如下。
1、asp下的301重定向代码
<%@ language=vbscript %>
<%
response.status=”301 moved permanently”
response.addheader “location”, “106/”
%>
2、asp.net下的301重定向代码
<script runat=”server”>
private void page_load(object sender, system.eventargs e)
{
response.status = “301 moved permanently”;
response.addheader(”location”,” 106/“);
}
</script>
3、php下的301重定向代码
header(”http/1.1 301 moved permanently”);
header(”location: 106/”);
exit();
第一行代码是强制下载;
第二行代码是给下载的内容指定一个名字;
第三行代码是把下载的内容读进文件中。
提示用户保存一个生成的 pdf 文件(content-disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框):
<?php教程2 header("content-type: application/force-download");
3 header("content-disposition: attachment; filename=ins.jpg");
4 readfile("imgs/test_zoom.jpg");
5 ?>
header() 函数向客户端发送原始的 http 报头。
认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 php 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
header(string,replace,http_response_code)
其它用法
<?php
// date in the past
header("expires: mon, 26 jul 1997 05:00:00 gmt");
header("cache-control: no-cache");
header("pragma: no-cache");
?>
$string = "this is a test";
echo str_replace(" is", " was", $string);
echo ereg_replace("( )is", "1was", $string); 其中1就是第一个括号中空格
echo ereg_replace("(( )is)", "2was", $string); 其中2就是第二个括号的空格
上面三行也就是把" is"替换为" was";都有空格的。
ereg_replace ( string pattern, string replacement, string string)
也就是说如果pattern中带有()得字符串(如;括号中有空格),那你的replacement就可以使用如1的字符串,那这个1就给可以用你第1个括号中字符串来替换,如果是2那就用第2个括号中的字符串替换.
括号从左到右,以左括号为准.
下面那个是去掉url中的如&page=1
符串比对解析并取代。
语法: string ereg_replace(string pattern, string replacement, string string);
返回值: 字符串
函数种类: 资料处理
内容说明
本函数以 pattern 的规则来解析比对字符串 string,欲取而代之的字符串为参数 replacement。返回值为字符串类型,为取代后的字符串结果。
使用范例
ken@freebsdrocks.com 在 16-mar-1999 提出的例子。
<?php教程
$text = 'this is a {1} day, not {2} and {3}.';
$daytype = array( 1 => 'fine',
2 => 'overcast',
3 => 'rainy' );
while (ereg ('{([0-9]+)}', $text, $regs)) {
$found = $regs[1];
$text = ereg_replace("{".$found."}", $daytype[$found], $text);
}
echo "$textn";
// this is a fine day, not overcast and rainy.
?>
ken@freebsdrocks.com 并同时提出具有相同功能的perl 程序范例如下:
$text = 'this is a {1} day, not {2} and {3}.';
%daytype = ( 1 => 'fine',
2 => 'overcast',
3 => 'rainy' );
$text =~ s/{(d+)}/$daytype{$1}/eg;
print "$textn";
php教程 效率的字符串处理方法
<?php
$str = array(
"helloworld",
"howareyou",
"cpufrequency",
"windows7ready",
"newedition2",
"downloadurllist",
"heisasuperhero",
);//你的解决方法
/*
正确添加空格后应为:
"helloworld" = "hello world"
"howareyou" = "how are you"
"cpufrequency" = "cpu frequency"
"windows7ready" = "windows 7 ready"
"newedition2" = "new edition 2"
"downloadurllist" = "download url list"
"heisasuperhero" = "he is a super hero"
*/?>
程序代码
function transfer($input) {
$newarray = array();
foreach($input as $i) {
$arr = str_split($i);
$word = '';
foreach($arr as $a) {
$ascii = ord($a);
$lastword = substr($word, -1);
$ascii_1 = ord($lastword);
$lastword_ = substr($word, -2, 1);
if($ascii > 64 && $ascii < 91) {
if($ascii_1 > 96 && $ascii_1 < 122) {
$word .= ' '.$a;
} else {
$word .= $a;
}
} elseif($ascii > 96 && $ascii < 122) {
if($ascii_1 > 64 && $ascii_1 < 91) {
if(strlen($word) == 1) {
$word .= $a;
} else {
if(ord($lastword_) == 32) {
$word .= $a;
} else {
$word = substr($word, 0, -1).' '.$lastword.$a;
}
}
} else {
$word .= $a;
}
} else {
if(strlen($word) == 0) {
$word .= $a;
} else {
$word .= ' '.$a;
}
}
}
$newarray[$i] = $word;
}
return $newarray;
}print_r(transfer($str));
在php教程使用curl时必须先在php.ini中开启extension=php_curl.dll前面的;去了,才行哦,curl是php中一款内置的浏览器,它可以模仿用户浏览信息进行网站浏览,等下面来看一实例。
function postpage($url)
{
$response = "";
$rd=rand(1,4);
$proxy='http://221.214.27.253:808';
if($rd==2) $proxy='http://222.77.14.56:8088';
if($rd==3) $proxy='http://202.98.123.126:8080';
if($rd==4) $proxy='http://60.14.97.38:8080';
if($url != "") {
$ch = curl_init($url);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_proxy, $proxy);
$response = curl_exec($ch);
if(curl_errno($ch)) $response = "";
curl_close($ch);
}
return $response;
}
curl包括部份函数
curl_close — close a curl session
curl_copy_handle — copy a curl handle along with all of its preferences
curl_errno — return the last error number
curl_error — return a string containing the last error for the current session
curl_exec — perform a curl session
curl_getinfo — get information regarding a specific transfer
curl_init — initialize a curl session
curl_multi_add_handle — add a normal curl handle to a curl multi handle
curl_multi_close — close a set of curl handles
curl_multi_exec — run the sub-connections of the current curl handle
curl_multi_getcontent — return the content of a curl handle if curlopt_returntransfer is set
curl_multi_info_read — get information about the current transfers
curl_multi_init — returns a new curl multi handle
curl_multi_remove_handle — remove a multi handle from a set of curl handles
curl_multi_select — wait for activity on any curl_multi connection
curl_setopt_array — set multiple options for a curl transfer
curl_setopt — set an option for a curl transfer
curl_version — gets curl version information
相关文章
- 这篇文章主要为大家详细介绍了ASP.NET购物车的实现过程,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22
- 在开发过程中,使用Visual Studio的断点调试功能可以很方便帮我们调试发现程序存在的错误,同样Visual Studio也支持对SQL Server里面的存储过程进行调试,下面就让我们看看具体的调试方法。...2021-09-22
Spring Boot项目@RestController使用重定向redirect方式
这篇文章主要介绍了Spring Boot项目@RestController使用重定向redirect方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-02ASP.NET Core根据环境变量支持多个 appsettings.json配置文件
这篇文章主要介绍了ASP.NET Core根据环境变量支持多个 appsettings.json配置文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22- 这篇文章主要介绍了记一次EFCore类型转换错误及解决方案,帮助大家更好的理解和学习使用asp.net core,感兴趣的朋友可以了解下...2021-09-22
- 这篇文章主要介绍了cmd命令的重定向输出 2>&1详解,需要的朋友可以参考下...2020-08-28
详解ASP.NET Core 中基于工厂的中间件激活的实现方法
这篇文章主要介绍了ASP.NET Core 中基于工厂的中间件激活的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-09-22asp.net通过消息队列处理高并发请求(以抢小米手机为例)
这篇文章主要介绍了asp.net通过消息队列处理高并发请求(以抢小米手机为例),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22ASP.NET单选按钮控件RadioButton常用属性和方法介绍
RadioButton又称单选按钮,其在工具箱中的图标为 ,单选按钮通常成组出现,用于提供两个或多个互斥选项,即在一组单选钮中只能选择一个...2021-09-22- 老谢目前做了一个新站,全站采用https协议访问,所以需要http重定向到https,只需要在.htaccess加入下面规则既可: 代码如下 复制代码 RewriteEngine On Rew...2016-01-28
ASP.NET 2.0中的数据操作:使用两个DropDownList过滤的主/从报表
在前面的指南中我们研究了如何显示一个简单的主/从报表, 该报表使用DropDownList和GridView控件, DropDownList填充类别,GridView显示选定类别的产品. 这类报表用于显示具有...2016-05-19- 大家知道,DOS下有一个不为大家所常用的命令——重定向命令,这个小东西非常有用,灵活的使用这个命令可以给我们带来很大的方便——无论是入侵还是防守抑或是系统应用,都会带来很大的便利,今天就让 我们来看几个重定向命令在安全方面的应用实例...2020-06-30
ASP.NET中iframe框架点击左边页面链接 右边显示链接页面内容
这篇文章主要介绍了ASP.NET中iframe框架点击左边页面链接,右边显示链接页面内容的实现代码,感兴趣的小伙伴们可以参考一下...2021-09-22- ASP.NET Web API具有与ASP.NET MVC类似的编程方式,ASP.NET Web API不仅仅具有一个完全独立的消息处理管道,而且这个管道比为ASP.NET MVC设计的管道更为复杂,功能也更为强大。下面创建一个简单的Web API项目,需要的朋友可以参考下...2021-09-22
- 这篇文章主要介绍了ASP.NET连接MySql数据库的2个方法及示例,使用的是MySQL官方组件和ODBC.NET,需要的朋友可以参考下...2021-09-22
- 这篇文章主要介绍了Asp.Net使用Bulk实现批量插入数据的方法,对于进行asp.net数据库程序设计非常有借鉴价值,需要的朋友可以参考下...2021-09-22
- 这篇文章主要介绍了获取DataTable选择第一行某一列值,需要的朋友可以参考下...2021-09-22
- 这篇文章介绍了Asp.net动态生成html页面的方法,有需要的朋友可以参考一下...2021-09-22
- 这篇文章主要介绍了ASP.Net中的async+await异步编程的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22
- 这篇文章主要介绍了详解ASP.NET Core Token认证,小编觉得挺不错的,现在分享给大家,也给大家做个参考。...2021-09-22