我写的程序到底哪出错了,为什么一直是wrong answer?

yks9991 2012-07-12 11:50:39
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
#define PI 3.1415926
#define Infinity 32767
struct Chimney
{
char shape;
int x;
int y;
};
void Input(int &m,char S1[100],Chimney C[100])
{
int i;
cin>>m;//输入烟囱的数量m(1<=m<=100)
cin>>S1;//输入从左到右烟囱的排列顺序
for(i=0;i<m;i++)
cin>>C[i].shape>>C[i].x>>C[i].y;//输入烟囱的形状、x坐标和y坐标
}
double Intersection(Chimney c1,Chimney c2)//计算两个烟囱的连线与x轴的交点
{
double p;
if(c1.y==c2.y)
p=Infinity;
else
p=(double)(c2.x*c1.y-c1.x*c2.y)/(c1.y-c2.y);
return p;
}
void Intersections(int m,int &pn,Chimney C[100],double P[5000])
{
int i,j,r;//i,j,r为循环变量
double p;
for(i=0;i<m-1;i++)//找出任意两个烟囱连线与x轴的交点,交点不重复,计算交点个数
for(j=i+1;j<m;j++)
{
p=Intersection(C[i],C[j]);
for(r=0;r<pn;r++)
if(P[r]==p)
break;
if(r==pn&&p!=Infinity)
P[pn++]=p;
}
for(i=0;i<pn-1;i++)//从小到大记录所有交点
for(j=i+1;j<pn;j++)
if(P[i]>P[j])
{
p=P[i];
P[i]=P[j];
P[j]=p;
}
}
void Compare(int m,int &n,int pn,Chimney C[100],double P[5000],char S1[100],double Intervals[10000])
{
int i,j,r;//i,j,r为循环变量
double X;//X表示Nick所在位置
double angle[100],A,T;//angle表示角度,T表示斜率
struct Chimney temp;
char S2[100];//表示从(X,0)看到的顺序
for(i=0;i<=pn;i++)
{
if(i==0)
X=P[i]-0.000001;
else
X=P[i-1]+0.000001;
for(j=0;j<m;j++)//求出所有烟囱与(X,0)点连线的倾角
{
if(X==C[j].x)
angle[j]=PI;
else
{
T=(double)C[j].y/(C[j].x-X);
angle[j]=atan(T);
if(angle[j]<0)
angle[j]+=PI;
}
}
for(j=0;j<m-1;j++)//倾角排序(由大到小)
for(r=j+1;r<m;r++)
if(angle[j]<angle[r])
{
A=angle[j];
angle[j]=angle[r];
angle[r]=A;
temp=C[j];
C[j]=C[r];
C[r]=temp;
}
for(j=0;j<m;j++)//比较S1和S2
{
S2[j]=C[j].shape;
if(S2[j]!=S1[j])
break;
}
if(j==m)//Nick可能在(X,0)处,记录X所在区间
{
if(i==0)
{
Intervals[0]=Infinity;
Intervals[1]=P[0];
}
else if(i==pn)
{
Intervals[2*n]=P[pn-1];
Intervals[2*n+1]=Infinity;
}
else
{
Intervals[2*n]=P[i-1];
Intervals[2*n+1]=P[i];
}
n++;
}
}
}
void Output(int n,double Intervals[10000])
{
int i;
cout<<n<<endl;//输出区间数n
for(i=0;i<2*n;i++)
{
if(Intervals[i]==Infinity)
cout<<"* ";
else
cout<<setprecision(7)<<Intervals[i]<<' ';
}
}
int main()
{
int m,n=0;//m为烟囱数,n为区间数
int pn=0;//pn为交点数
struct Chimney C[100];//为所有烟囱的记录
char S1[100];//S1表示Nick看到的烟囱的顺序
double P[5000];//交点
double Intervals[10000];//Intervals记录区间的两端点
Input(m,S1,C);
Intersections(m,pn,C,P);
Compare(m,n,pn,C,P,S1,Intervals);
Output(n,Intervals);
return 0;
}

...全文
423 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hen_hao_ji 2012-07-24
  • 打赏
  • 举报
回复
网上搜下别人的解题报告看下
kingdom_0 2012-07-24
  • 打赏
  • 举报
回复
自己调试吧。
baichi4141 2012-07-24
  • 打赏
  • 举报
回复
ACM题需要考虑特殊数据和极限数据
gongxujun 2012-07-24
  • 打赏
  • 举报
回复
设断点,看具体值吧
tongzhipeng5699 2012-07-12
  • 打赏
  • 举报
回复
VS编译器 F9打断点,F10 F11两种单步方式。
然后再界面中可以看到变量的值得变化,等等。
wsxxiaohao 2012-07-12
  • 打赏
  • 举报
回复
都没有题目的地址,楼主还是自己去调试吧。参考ACM里面的讨论。
moou00 2012-07-12
  • 打赏
  • 举报
回复
代码太长了,自己f9慢慢调试吧
tzg_dzq 2012-07-12
  • 打赏
  • 举报
回复
调试方法:
1:设断点
2:分段调试,即注释一些语句,依次排除语句错误
3:去函数调试,即去掉一些函数,一个函数一个函数调试
4:单独调试函数,即注释掉函数内部所有语句,看函数调用是否正确
5:变量值是否正确,变量地址是否正确
BNUEP Offline Judge 北京师范大学珠海分校离线评测系统是在具备题目测试数据的情况下,能无联网自动评测ACM/ICPC模式的源代码评测系统(即本地测试工具、评测机)。它主要有以下功能(所有的功能都无需联网,在本机即可实现): *评测核心功能: 基本具备Online Judge的判题核心功能,如编译代码、内存限定,时间限定,获取代码长度等; *支持多种语言: 1.0 Beta2版本支持C/C++、Pascal、C#、JAVA; *出题模式 可以在有标准输入数据和标准程序的情况下,由系统产生标准输出数据,并可批量保存,同时自动命名标准输出数据的后缀; *文本高亮对比 在判题后,可以直接在本系统中将自己的程序输出和标准输出进行高亮的文本差异对比,操作类似于一些文本对比软件,在一定程度上可以较方便地发现WA代码的出错细节; *支持不限时执行代码 这个功能可以在一定程度上检测TLE代码的算法是否正确的,当然,不能是跑一天都没跑出来的程序; *打包与加密测试数据 使用加密后的数据可以正常判题,但不显示标准输出。这个功能是为了弥补放出去给别人评测的测试数据是明文的缺陷。加密之后评测方就看不到测试数据。这样就既可以实现离线评测,又可以实现Online Judge上的对测试数据屏蔽; ACM-ICPC简介: ACM国际大学生程序设计竞赛(简称ACM-ICPC)是由国际计算机界具有悠久历史的权威性组织ACM学会(Association for Computing Machinery)主办,是世界上公认的规模最大、水平最高、参与人数最多的大学生程序设计竞赛,其宗旨是使大学生能通过计算机充分展示自己分析问题和解决问题的能力。 ACM-ICPC的每一道题,都具备题目、需求描述、输入格式描述、输出格式描述、样例输入和样例输出共六大信息,有些题目还有一定的提示。此外,裁判还额外存储了关于该题的一组或多组对选手屏蔽的标准输入和标准输出数据,这些测试数据已经经过验证符合题意要求。当用户提交一道题目的源码之后,裁判会将该源码放入评测系统中编译运行,并使用标准输入作为用户程序的输入,然后获取用户程序的输出,接着,将用户程序输出和标准输出比较,最后返回给用户一个评判结果。评判结果包括:Accepted(测试通过)、Compile Error(编译失败)、Memory Limit Exceed(内存超出限制)、Presentation Error(格式错误)、Runtime Error(运行时错误,可能是数组越界,改只读的内存,除零,栈或堆溢出等错误)、Time Limit Exceed(时间超出限制)、Wrong Answer(答案错误)等。
百度首页 | 百度空间 | 登录 广告停放提高网站流量,centos学习 主页博客相册|个人档案 查看文章
.htaccess怎么用2007-05-16 14:04(文章来源)http://www.dnpark.com.cn/news/mm/www/1179329504375ZKlMSgYr.html

Apache服务器的.htaccess是一个非常强大的分布式配置文件,学会使用.htaccess,对虚拟主机用户来说,可以实现众多的功能。这里有一篇很容易让人理解的.htaccess介绍,作为入门文章非常的适合。文章最初来自freewebmasterhelp.com,QiRan作了简单的中文翻译,我将加以完善。

Part 1 – Introduction介绍
Part 2 - .htaccess Commande命令
Part 3 - Password protection密码保护
Part 1 – Introduction介绍

Introduction 介绍

In this tutorial you will find out about the .htaccess file and the power it has to improve your website. Although .htaccess is only a file, it can change settings on the servers and allow you to do many different things, the most popular being able to have your own custom 404 error pages. .htaccess isn't difficult to use and is really just made up of a few simple instructions in a text file.
从本指南中,你将可以学习到有关.htaccess文件及其功能的知识,并用以优化你的网站。尽管.htaccess只是一个文件,但它可以更改服务器的设置,允许你做许多不同的事情,最流行的功能是您可以创建自定义的“404 error”页面。.htaccess 并不难于使用,归根结底,它只是在一个text文档中添加几条简单的指令而已。

Will My Host Support It? 我的主机支持它吗?

This is probably the hardest question to give a simple answer to. Many hosts support .htaccess but don't actually publicise it and many other hosts have the capability but do not allow their users to have a .htaccess file. As a general rule, if your server runs Unix or Linux, or any version of the Apache web server it will support .htaccess, although your host may not allow you to use it.
这可能很难用简单的答案来回答。许多主机支持.htaccess,但实际上并不会特别声明,许多其他类型的主机有能力但并不允许他们的用户使用.htaccess。一般来说,如果你的主机使用Unix或Linux系统,或任何版本的Apache网络服务器,从理论上都是支持.htaccess的,尽管你的主机服务商可能不允许你使用它。

A good sign of whether your host allows .htaccess files is if they support password protection of folders. To do this they will need to offer .htaccess (although in a few cases they will offer password protection but not let you use .htaccess). The best thing to do if you are unsure is to either upload your own .htaccess file and see if it works or e-mail your web host and ask them.
判断你的主机是否允许.htaccess,一个标志很好的是它是否支持文件夹密码保护。为达到此功能,主机服务商需要使用.htaccess(当然,少数情况下他们虽提供密码保护功能,但却并不允许你使用.htaccess)。如果你不确定自己的主机是否支持.htaccess,最好的办法是上传你自己的.htaccess文件看看是否有用,或者直接发送e-mail向你的主机服务商咨询。

What Can I Do? 我该怎么做?

You may be wondering what .htaccess can do, or you may have read about some of its uses but don't realise how many things you can actually do with it.
你可能疑惑.htaccess到底能做些什么,或者你可能曾知道它的一些功能但并不真正了解你实际到底可以用它来做多少事情。

There is a huge range of things .htaccess can do including: password protecting folders, redirecting users automatically, custom error pages, changing your file extensions, banning users with certian IP addresses, only allowing users with certain IP addresses, stopping directory listings and using a different file as the index file.
.htaccess可以做大量的事情,包括:文件夹密码保护、用户自动重定向、自定义错误页面、改变你的文件扩展名、封禁特定IP地址的用户、只允许特定IP地址的用户、禁止目录列表,以及使用其他文件作为index文件。

Creating A .htaccess File 创建一个.htaccess文档

Creating a .htaccess file may cause you a few problems. Writing the file is easy, you just need enter the appropriate code into a text editor (like notepad). You may run into problems with saving the file. Because .htaccess is a strange file name (the file actually has no name but a 8 letter file extension) it may not be accepted on certain systems (e.g. Windows 3.1). With most operating systems, though, all you need to do is to save the file by entering the name as:
创建.htaccess文件也许会给你带来一些困难。文件很容易,你只需要在文字编缉器(例如:字板)里下适当的代码。真正困难的可能是文件的保存,因为.htaccess是一个古怪的文件名(它事实上没有文件名,只有一个由8个字母组成的扩展名),而在一些系统(如windows 3.1)中无法接受这样的文件名。在大多数的操作系统中,你需要做的是将文档保存成名为:

".htaccess"
(including the quotes). If this doesn't work, you will need to name it something else (e.g. htaccess.txt) and then upload it to the server. Once you have uploaded the file you can then rename it using an FTP program.
(包括引号)。如果这也不行,你需要将其先命名为其它名字(例如htaccess.txt),再将其上传到服务器上,之后直接使用FTP软件来重命名。

Warning 警告

Before beginning using .htaccess, I should give you one warning. Although using .htaccess on your server is extremely unlikely to cause you any problems (if something is wrong it simply won't work), you should be wary if you are using the Microsoft FrontPage Extensions. The FrontPage extensions use the .htaccess file so you should not really edit it to add your own information. If you do want to (this is not recommended, but possible) you should download the .htaccess file from your server first (if it exists) and then add your code to the beginning.
在使用.htaccess之前,我必须给你一些警告。虽然在服务器上使用.htaccess绝对不太可能给你带来任何麻烦(如果有些东西错了,它只是没效用罢了),但如果你使用Microsoft FrontPage Extensions,就必须特别小心。因为FrontPage Extensions本身使用了.htaccess,因此你不能编辑它并加入你自己的信息。如果确实有这方面的需要(并不推荐,但是可能),你应该先从服务器上下载.htaccess文档(如果存在),之后在前面加上你的代码。

Custom Error Pages 自定义错误页

The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host's error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found).
我要介绍的.htaccess的第一个应用是自定义错误页面,这将使你可以拥有自己的、个性化的错误页面(例如找不到文件时),而不是你的服务商提供的错误页或没有任何页面。这会让你的网站在出错的时候看上去更专业。你还可以利用脚本程序在发生错误的时候通知你(例如我使用Free Webmaster Help的PHP脚本程序,当找不到页面的时候自动e-mail给我)。

You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:
你所知道的任何页面错误代码(像404找不到页面),都可以通过在.htaccess文件里加入下面的文字将其变成自定义页面:

rrorDocument errornumber /file.html
For example if I had the file notfound.html in the root direct
ory of my site and I wanted to use it for a 404 error I would use:
举例来说,如果我的根目录下有一个nofound.html文件,我想使用它作为404 error的页面:

ErrorDocument 404 /notfound.html
If the file is not in the root directory of your site, you just need to put the path to it:
如果文件不在网站的根目录下,你只需要把路径设置为:

ErrorDocument 500 /errorpages/500.html
These are some of the most common errors:
以下是一些最常用的错误:

401 - Authorization Required 需要验证
400 - Bad request 错误请求
403 - Forbidden 禁止
500 - Internal Server Error 内部服务器错误
404 - Wrong page 找不到页面
Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.
接下来,你要做的只是创建一个错误发生时显示的文件,然后把它们和.htaccess一起上传。


Part 2 - .htaccess 命令

Introduction 介绍

In the last part I introduced you to .htaccess and some of its useful features. In this part I will show you how to use the .htaccess file to implement some of these.
在上一部分,我已经简单介绍了.htaccess以及它的一些有用功能,在这一部分,我将向你演示如何使用.htaccess文档去实现这些功能。

Stop A Directory Index From Being Shown 停示显示目录列表

Sometimes, for one reason or another, you will have no index file in your directory. This will, of course, mean that if someone types the directory name into their browser, a full listing of all the files in that directory will be shown. This could be a security risk for your site.
有些时候,由于某种原因,你的目录里没有index文件,这意味着当有人在浏览器地址栏键入了该目录的路径,该目录下所有的文件都会显示出来,这会给你的网站留下安全隐患。

To prevent against this (without creating lots of new 'index' files, you can enter a command into your .htaccess file to stop the directory list from being shown:
为避免这种情况(而不必创建一堆的新index文件),你可以在你的.htaccess文档中键入以下命令,用以阻止目录列表的显示:

Options -Indexes
Deny/Allow Certian IP Addresses 阻止/允许特定的IP地址

In some situations, you may want to only allow people with specific IP addresses to access your site (for example, only allowing people using a particular ISP to get into a certian directory) or you may want to ban certian IP addresses (for example, keeping disruptive memembers out of your message boards). Of course, this will only work if you know the IP addresses you want to ban and, as most people on the internet now have a dynamic IP address, so this is not always the best way to limit usage.
某些情况下,你可能只想允许某些特定IP的用户可以访问你的网站(例如:只允许使用特定ISP的用户进入某个目录),或者想封禁某些特定的IP地址(例如:将低级用户隔离于你的信息版面外)。当然,这只在你知道你想拦截的IP地址时才有用,然而现在网上的大多数用户都使用动态IP地址,所以这并不是限制使用的常用方法。

You can block an IP address by using:
你可以使用以下命令封禁一个IP地址:

deny from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will block a whole range.
这里的000.000.000.000是被封禁的IP地址,如果你只指明了其中的几个,则可以封禁整个网段的地址。如你输入210.10.56.,则将封禁210.10.56.0~210.10.56.255的所有IP地址。

You can allow an IP address by using:
你可以使用以下命令允许一个IP地址访问网站:

allow from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will allow a whole range.
被允许的IP地址则为000.000.000.000,你可以象封禁IP地址一样封禁整个网段。

If you want to deny everyone from accessing a directory, you can use:
如果你想阻止所有人访问该目录,则可以使用:

deny from all
but this will still allow scripts to use the files in the directory.
不过这并不影响脚本程序使用这个目录下的文档。

Alternative Index Files 替换index文件

You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to!
也许你不想一直使用index.htm或index.html作为目录的索引文件。举例来说,如果你的站点使用PHP文件,你可能会想使用index.php来作为该目录的索引文档。当然也不必局限于“index”文档,如果你愿意,使用.htaccess你甚至能够设置foofoo.balh来作为你的索引文档!

Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).
这些互为替换的索引文件可以排成一个列表,服务器会从左至右进行寻找,检查哪个文档在真实的目录中存在。如果一个也找不到,它将会把目录列表显示出来(除非你已经关闭了显示目录文件列表)。

DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm
Redirection 重定向

One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. The following can be done to redirect a specific file:
.htaccess最有用的功能之一就是将请求重定向到同站内或站外的不同文档。这在你改变了一个文件名称,但仍然想让用户用旧地址访问到它时,变的极为有用。另一个应用(我发现的很有用的)是重定向到一个长URL,例如在我的时事通讯中,我可以使用一个很简短的URL来指向我的会员链接。以下是一个重定向文件的例子:

Redirect /location/from/root/file.ext
http://www.othersite.com/new/file/location.xyz
In this above example, a file in the root directory called oldfile.html would be entered as:
上述例子中,访问在root目录下的名为oldfile.html可以键入:

/oldfile.html
and a file in the old subdirectory would be entered as:
访问一个旧次级目录中的文件可以键入:

/old/oldfile.html
You can also redirect whole directoires of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one:
你也可以使用.htaccess重定向整个网站的目录。假如你的网站上有一个名为olddirectory的目录,并且你已经在一个新网站 http://www.newsite.com/newdirectory/上建立了与上相同的文档,你可以将旧目录下所有的文件做一次重定向而不必一一声明:

Redirect /olddirectory http://www.newsite.com/newdirectory
Then, any request to your site below /olddirectory will bee redirected to the new site, with the
extra information in the URL added on, for example if someone typed in:
这样,任何指向到站点中/olddirectory目录的请求都将被重新指向新的站点,包括附加的额外URL信息。例如有人键入:

http://www.youroldsite.com/olddirecotry/oldfiles/images/image.gif
They would be redirected to:
请求将被重定向到:

http://www.newsite.com/newdirectory/oldfiles/images/image.gif
This can prove to be extremely powerful if used correctly.
如果正确使用,此功能将极其强大。

Part 3 – 密码保护

Introduction 介绍

Although there are many uses of the .htaccess file, by far the most popular, and probably most useful, is being able to relaibly password protect directories on websites. Although JavaScript etc. can also be used to do this, only .htaccess has total security (as someone must know the password to get into the directory, there are no 'back doors')
尽管有各种各样的.htaccess用法,但至今最流行的也可能是最有用的做法是将其用于网站目录可靠的密码保护。尽管JavaScrip等也能做到,但只有.htaccess具有完美的安全性(即访问者必须知晓密码才可以访问目录,并且绝无“后门”可走)。

The .htaccess File 密码保护的.htaccess文件

Adding password protection to a directory using .htaccess takes two stages. The first part is to add the appropriate lines to your .htaccess file in the directory you would like to protect. Everything below this directory will be password protected:
利用.htaccess将一个目录加上密码保护分两个步骤。第一步是在你的.htaccess文档里加上适当的几行代码,再将.htaccess文档放进你要保护的目录下:

AuthName "Section Name"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user
There are a few parts of this which you will need to change for your site. You should replace "Section Name" with the name of the part of the site you are protecting e.g. "Members Area".
你可能需要根据你的网站情况修改一下上述内容中的一些部分,如用被保护部分的名字"Members Area",替换掉“Section Name”。

The /full/parth/to/.htpasswd should be changed to reflect the full server path to the .htpasswd file (more on this later). If you do not know what the full path to your webspace is, contact your system administrator for details.
/full/parth/to/.htpasswd则应该替换为指向.htpasswd文件(后面详述该文档)的完整服务器路径。如果你不知道你网站空间的完整路径,请询问一下你的系统管理员。

The .htpasswd File 密码保护的.htpasswd文件

Password protecting a directory takes a little more work than any of the other .htaccess functions because you must also create a file to contain the usernames and passwords which are allowed to access the site. These should be placed in a file which (by default) should be called .htpasswd. Like the .htaccess file, this is a file with no name and an 8 letter extension. This can be placed anywhere within you website (as the passwords are encrypted) but it is advisable to store it outside the web root so that it is impossible to access it from the web.
目录的密码保护比.htaccess的其他功能要麻烦些,因为你必须同时创建一个包含用户名和密码的文档,用于访问你的网站,相关信息(默认)位于一个名为.htpasswd的文档里。像.htaccess一样,.htpasswd也是一个没有文件名且具有8位扩展名的文档,可以放置在你网站里的任何地方(此时密码应加密),但建议你将其保存在网站Web根目录外,这样通过网络就无法访问到它了。

Entering Usernames And Passwords 输入用户名和密码

Once you have created your .htpasswd file (you can do this in a standard text editor) you must enter the usernames and passwords to access the site. They should be entered as follows:
创建好.htpasswd文档后(可以通过文字编辑器创建),下一步是输入用于访问网站的用户名和密码,应为:

username:password
where the password is the encrypted format of the password. To encrypt the password you will either need to use one of the premade scripts available on the web or write your own. There is a good username/password service at the KxS site which will allow you to enter the user name and password and will output it in the correct format.
“password”的位置应该是加密过的密码。你可以通过几种方法来得到加密过的密码:一是使用一个网上提供的permade脚本或自己一个;另一个很不错的username/password加密服务是通过KxS网站,这里允许你输入用户名及密码,然后生成正确格式的密码。

For multiple users, just add extra lines to your .htpasswd file in the same format as the first. There are even scripts available for free which will manage the .htpasswd file and will allow automatic adding/removing of users etc.
对于多用户,你只需要在.htpasswd文档中新增同样格式的一行即可。另外还有一些免费的脚本程序可以方便地管理.htpasswd文档,可以自动新增/移除用户等。

Accessing The Site 访问网站

When you try to access a site which has been protected by .htaccess your browser will pop up a standard username/password dialog box. If you don't like this, there are certain scripts available which allow you to embed a username/password box in a website to do the authentication. You can also send the username and password (unencrypted) in the URL as follows:
当你试图访问被.htaccess密码保护的目录时,你的浏览器会弹出标准的username/password对话窗口。如果你不喜欢这种方式,有些脚本程序可以允许你在页面内嵌入username/password输入框来进行认证,你也可以在浏览器的URL框内以以下方式输入用户名和密码(未加密的):

http://username:password@www.website.com/directory/
Summary 小结

.htaccess is one of the most useful files a webmaster can use. There are a wide variety of different uses for it which can save time and increase security on your website.
.htaccess是一个站点管理员可以应用的强大工具,有更多的变化以适应不同的用途,可以节约时间及提高网站的安全性。

相关阅读:


KxS Password Encrypter
Apache .htaccess Documentation
More .htaccess Sites
Related Reading

.htaccess的特别说明


启用.htaccess,需要修改httpd.conf,启用AllowOverride,并可以用AllowOverride限制特定命令的使用
如果需要使用.htaccess以外的其他文件名,可以用AccessFileName指令来改变。例如,需要使用.config ,则可以在服务器配置文件中按以下方法配置:

AccessFileName .config
一般情况下,不应该使用.htaccess文件,除非你对主配置文件没有访问权限。有一种很常见的误解,认为用户认证只能通过.htaccess文件实现,其实并不是这样,把用户认证在主配置文件中是完全可行的,而且是一种很好的方法。.htaccess文件应该被用在内容提供者需要针对特定目录改变服务器的配置而又没有root权限的情况下。如果服务器管理员不愿意频繁修改配置,则可以允许用户通过.htaccess文件自己修改配置,尤其是ISP在同一个机器上运行了多个用户站点,而又希望用户可以自己改变配置的情况下。虽然如此,一般都应该尽可能地避免使用.htaccess文件。任何希望放在.htaccess文件中的配置,都可以放在主配置文件的段中,而且更高效。避免使用.htaccess文件有两个主要原因,即性能和安全。


类别:php+mysql+apache+zend | 添加到搜藏 | 浏览(40) 网友评论: 发表评论:姓 名: 注册 | 登录 *姓名最长为50字节

网址或邮箱: (选填)

内 容:

验证码: 请输入下图中的四位验证码,字母不区分大小
看不清?




©2007 Baidu

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧