laravel更改public目录名(去掉地址里的public)

话说今天有一个前同事问我初接触laravel框架,发现地址栏里有public名,怎么去除。

其实度娘或者谷歌一下就可以得到一个简单的解决办法(修改server.php文件),但实际上laravel(我的前同事就经常给打成lavarel)的结构是尽量避免其他系统文件可以被直接使用URL访问,那么正确的放置方式是,除了PUBLIC目录内的文件上传至环境主机WEB目录之外,其他都放置在与WEB根目录同级的位置。

我的这位前同事使用的是AMH框架,只需要将内容使用SSH上传或者给WEB之前的主标志域名一级目录给一个775甚至777权限,上传完毕再改回来即可

/home/wwwroot/环境名/domain/主标志域名/

具体LINUX目录权限操作命令可自行搜索。

至于有人问我没有VPS只有一个虚拟主机,个人建议还是放弃折腾框架吧,用个现成的CMS或者BLOG不好么?

 

判断移动设备的function isMobile()(PHP)

不废话上代码,使用方法就是

1
2
3
4
<?php 
if(isMobile()){}
if(!isMobile()){}
 ?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function isMobile() {
 
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$mobile_agents = Array("240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi", "htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin", "vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte");
 
$is_mobile = false;
foreach ($mobile_agents as $device) {
  if (stristr($user_agent, $device)) {
    $is_mobile = true;
    break;
  }
}
return $is_mobile;
}

一个PHP裁切字符的function

主要应用在THINKPHP的模板上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function msubpost($str, $start=0, $length=18, $charset="utf-8", $suffix=false) {
  if(strlen($str) > ($length*2)){
    $suffix = true;
  }else{
    $suffix = false;
  }
  if(function_exists('iconv_substr') || $charset=="utf-8") {
    $slice = iconv_substr($str,$start,$length,$charset);
    if(false === $slice) {
        $slice = '';
    }
  }elseif(function_exists("mb_substr")){
    $slice = mb_substr($str, $start, $length, $charset);
  }else{
    $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
    $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
    $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
    $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
    preg_match_all($re[$charset], $str, $match);
    $slice = join("",array_slice($match[0], $start, $length));
  }
  return $suffix ? $slice.'...' : $slice;
}

THINKPHP的HTTP_USER_AGENT模版判定

众所周知THINKPHP的模板里面不建议使用原生PHP代码,所以,判断用户USER AGENT怎么办?

其实很简单,直接套用……这样就实现了动态加载,而并非HTML或者JS来判断user agent

1
<if condition="strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0')">判断之后的内容</if>

WDCP升级PHP和MYSQL

WDCP作为中国人自己的VPS控制面板,整体上来说非常不错,但默认的PHP版本是5.2.17,MySQL是5.1.63,实在有点低,甚至低到了部分PHP框架和程序都无法运行(例如本站使用的wordpress),所以必须要升级才行。下面就分步骤简述升级流程

升级php 5.3

登录SSH,按顺序执行下面的命令

1
wget http://down.wdlinux.cn/in/php_up53.sh
1
sh php_up53.sh

等待屏幕上停止代码滚动,并提示php update is OK就表示升级成功了,可以使用PHP INFO看一下版本。
WDCP升级PHP和MYSQL