分類
程序 网站

使用header对页面授权

此法效果类似路由器的登录页面,会弹出一个登录页。适合一个admin的简单授权管理。结束会话(关闭浏览器)后授权即失效。

首先创建authorize.php,这样只需在需要授权的页面引用即可。内容如下:

<?php
  // User name and password for authentication
  $username = 'rock';
  $password = 'roll';

  if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
    ($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
    // The user name/password are incorrect so send the authentication headers
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="特征码"');//需要相同认证的页面标记
    exit('<h2>Hi</h2>Display this message when user select CANCEL.');
  }
?>

在需要授权的页面开始处添加:

<?php
  require_once('authorize.php');
?>

需要注意的是上面这段引用,即授权代码必须放在最前面,其<?php前不能有任何字符,即使是空格也不行。

分類
程序

java批量下图

这个代码没什么太大用途,权当复习一下java,里面的例外也处理。作用就是能下载http://www.style.com/fashionshows/complete/slideshow/F2014MEN-AMCQUEEN/这个相册里的30张图。

package fatch;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 *
 * @author 42
 */
public class Fatch {

    /**
     * 本程序获取http://www.style.com/fashionshows/complete/slideshow/F2014MEN-AMCQUEEN/相册中的30张图片
     * 通过查看图片属性发现其文件名有简单规律,虽不连续但是是有顺序的
     * first,last是网址的前半部分和后半部分
     * 先判断文件是否存在,然后将文件下载到本地
     */
    public static void main(String[] args) throws MalformedURLException, IOException {
        String imagesource="";
        String first="http://www.style.com/fashion-shows/fall-2014-menswear/london/alexander-mcqueen/collection/_ARC0";
        String last=".1366x2048.JPG";
        
        InputStream inputStream;  
        byte[] getData = null;
        for(int i=1,x=0;x<30&&i<=500;i++){
            if(i<10){
                imagesource=first+"00"+i+last;
            }else if((i>=10)&&(i<100)){
                imagesource=first+"0"+i+last;
            }else if((i>=100)&&(i<1000)){
                imagesource=first+i+last;
            }
        URL url = new URL(imagesource);  
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();  
        try {
            inputStream = conn.getInputStream();      //通过输入流获得图片数据
            getData = readInputStream(inputStream);     //获得图片的二进制数据  
        } catch (IOException ex) {
            getData=null;
        }
        
        if(getData!=null){
        File imageFile = new File(i+".JPG");    
        FileOutputStream fos = new FileOutputStream(imageFile);
        fos.write(getData);             
        fos.close();  
          
        System.out.println(x+"picture(s) downloaded"); 
        x++;
        }
        }
        
    }  
  
    public static  byte[] readInputStream(InputStream inputStream) throws IOException {  
        byte[] buffer = new byte[1024];  
        int len = 0;  
        ByteArrayOutputStream bos = new ByteArrayOutputStream();  
        while((len = inputStream.read(buffer)) != -1) {  
            bos.write(buffer, 0, len);  
        }  
          
        bos.close();  
        return bos.toByteArray();
    }
}
分類
程序 网站

用php处理表单的数据

下面代码在接收到数据后先将数据储存与数据库,再将数据以电子邮件方式通知自己。

<?php
$author=$_POST["name"];$email=$_POST["email"];$title=$_POST["subject"];$message=$_POST["message"];
$con=mysql_connect("数据库地址","数据库用户名","数据库密码");
if(!$con){
	die('Could not connect: '.mysql_error());
	}
mysql_query("set names utf8");
mysql_select_db("数据库名",$con);
mysql_query("INSERT INTO `数据表名` (`id`, `date`, `author`, `email`, `title`, `message`) VALUES (NULL, CURRENT_TIMESTAMP, '$author', '$email', '$title', '$message')");
mysql_close($con);
$myNotify = "Name:$authornEmail:$emailnTitle:$titlenMessage:$message";
$myNotify = wordwrap($myNotify,70);
mail("自己的邮箱@gmail.com","your tittle",$myNotify,'From:发送自@ft.wupo.info');//邮件标题如果有中文要进行编码,否则会乱码,故这里没有使用$title
echo ""; 
exit;
?>
分類
其它

将word表格导入cdr

如果直接复制word中的表格,贴入cdr后会对不齐,而且表格的底色等也会丢失。现在发现一个导入后跟word里显示一样的方法。

现将表格单独保存并用虚拟打印机打印成pdf,然后再导入cdr,选择曲线方式导入。这样就完美了,表格效果和word中一模一样。

需要提醒的是我用的是装Adobe Acrobat时自带的Adobe PDF虚拟打印机,效果很好。我还试了Solid PDF Tools的虚拟打印机,导出的pdf再导入cdr效果就很差。

分類
网站

wordpress301重定向

这个说来简单,但是还是要记一下的。尤其是wordpress开启了固定链接,本身已经有个.htaccess文件了。在加入转向代码时就要注意顺序,要把转向链接放在前面。我是从pggdt.mypressonline.com转到ft.wupo.info的,整个.htaccess文件内容如下:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^pggdt.mypressonline.com [NC]
RewriteRule ^(.*)$ http://ft.wupo.info/$1 [L,R=301]

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


# END WordPress
分類
网站

不推荐使用awardspace空间

由于freeidc换了域名,服务仍旧正常,我就又回来了,现在的域名是yuns.pw。awardspace.com用的太难受了。

  • 单个文件大小限制2M,我用的webp图片,也没什么问题。
  • 空间250M,月流量5G,也还可以。
  • 装完wordpress发现无法修改之前的文章,后来我直接在数据库修改的。
  • 再后来发现添加新文章有时也会莫名失败,无法发表,感觉就是内容稍长一点而而已。
  • Akismet无法使用,完全连不上Akismet的服务器。
  • 用我家的联通网络访问巨慢,公司铁通到还过得去。但是cpanel无论那个网络都慢的想死。
  • g+代码无效。

本文更新於 2014/09/04。

分類
Linux

Ubuntu安装fcitx中文输入法

听说fcitx中文输入法是较为先进的中文输入法,而且拥有相对漂亮的皮肤,当然亮点还是能支持云输入法,众多优点当然要试一下啦。要安装fcitx中文输入法,依此在终端执行如下命令:

<code>sudo add-apt-repository ppa:wengxt/fcitx-nightly</code>
<code>sudo apt-get update</code>
<code>sudo apt-get install fcitx fcitx-config-gtk fcitx-sunpinyin</code>
<code>sudo apt-get install fcitx-table-all</code>

下面两条命令是可选的,第一个是设置fcitx为默认输入法,第二个是为防止乱码所安装的uming字体。

<code>im-switch -s fcitx -z default</code>
<code>sudo apt-get install ttf-arphic-uming</code>

最后需要重启生效。如果没有中文输入法出现,可以在Configuation里点“+”,然后反选Only Show Current Language,在下面输入框里输pinyin就可以添加中文输入法了。默认Ctrl+Space切换输入法,Shift切换语言,中文下按Enter输入英文。