//获得当前的脚本网址 function GetCurUrl(){ if(!empty($_SERVER["REQUEST_URI"])){ $scriptName = $_SERVER["REQUEST_URI"]; $nowurl = $scriptName; }else{ $scriptName = $_SERVER["PHP_SELF"]; if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName; else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"]; } return $nowurl; }原文:http://www.jb51.ne...
通常PHP都做http方式请求了,可以使用GET or POST方式接收参数,有些时候需要在shell命令下把PHP当作脚本执行,比如定时任务。这就涉及到在shell命令下如何给php传参的问题,通常有三种方式传参。一、使用$argv or $argc参数接收<?php
/*** 使用 $argc $argv 接受参数*/
echo "接收到{$argc}个参数";
print_r($argv);以下是测试的结果二、使用getopt函数(推荐使用这种方法)<?php
/*** 使用 getopt函数*/
$param_arr = getopt(‘a...
今天在windows平台的cmd 或 shellpower 中,执行php脚本,输出中文会乱码。最终想到一个解决办法,就是在php 脚本里执行 cmd 命令去修改当前 页码字符集 <?phpexec("CHCP 65001");// coding... 如果别的编码根据下面的自己换吧!chcp 65001 就是换成UTF-8chcp 936 可以换回默认的GBKchcp 437 是美国英语原文:https://www.cnblogs.com/-mrl/p/12206588.html
<?php
$con = mysql_connect("192.168.1.5:3306","root","123");
if (!$con){die(‘Could not connect: ‘ . mysql_error());}mysql_select_db("e_wms", $con);function varchar(){$string = ‘abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789‘;$str = ‘‘;for ($i=0; $i < 10; $i++) { $str.= $string[rand(0,strlen($string)-1)];}return$str;
}functionnumber(){$string = ‘123456789‘;$str = ‘‘;for ($i=0; $i < 4;...
关于用php 获取当前脚本的url很多朋友会说很简单,但是要获取很详细的就要经过多次判断哦。$PHP_TIME = time();$PHP_SELF = isset($_SERVER[‘PHP_SELF‘]) ? $_SERVER[‘PHP_SELF‘] : (isset($_SERVER[‘SCRIPT_NAME‘]) ? $_SERVER[‘SCRIPT_NAME‘] : $_SERVER[‘ORIG_PATH_INFO‘]);/**获取当前运行的脚本名: 刚开始看是不是有点乱呢。 咋没用if else 呢。 看这样的东西。我们最好从右看到左。这样比较好明白点。$_SERVER[...
最近服务器时不时出现Nginx 502 Bad Gateway,如果在电脑旁边还好,要是半夜或者出去了,怎么办?
没关系,写个脚本检测服务状态,发现异常,自动重启。
自动重启脚本:复制代码 代码如下:
<?php
$url = ‘http://blog.rebill.info‘;
$cmd = ‘/usr/local/php/sbin/php-fpm restart‘;
for($i = 0; $i < 5; $i ++){
$exec = "curl connect-timeout 3 -I $url 2>/dev/null";
$res = shell_exec($exec);
...
本文实例讲述了php返回json数据函数的用法,分享给大家供大家参考。具体方法如下:json_encode()函数用法:echo json_encode(array(‘a‘=>‘bbbb‘,‘c‘=>‘ddddd‘); 这样就会生成一个标准的json格式的数据<?php
//需要执行的SQL语句
//单条$sql="select id,name from tbl_user where id=1";
//多条数据
//$sql="select id,name from tbl_user";
//调用conn.php文件进行数据库操作require(‘Conn.php‘);
//提示操作成功信息,注...
1. 出现“未找到文件“类似的错误时候,检查include文件的位置是否正确,下面引用php手册页面的原话: Files for including are first looked in include_path relative to the current working directory and then in the directory of the current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first...
#!/usr/bin/env python
# encoding: utf-8import time
import os
import sys
import logging#create logger
logger = logging.getLogger("phpfile")
logger.setLevel(logging.DEBUG)
#create console handler and set level to error
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
#create file handler and set level to debug
fh = logging.FileHandler("phpfile.log")
fh.setLevel(logging.DEBUG)
#create formatte...
LNMP一键安装包 PHP自动升级脚本2011年03月15日 上午 | 作者:VPS侦探前一段时间完成了lnmp一键安装包的PHP自动升级脚本,今天发布出来,如果想升级PHP版本的lnmp用户可以试用一下。支持目前lnmp的所有版本。只能有低版本升级到高版本不能降级。可以升级到现有PHP 5.2.14到PHP 5.3.5除5.3.0、5.3.1、5.3.2的几个过渡版本之外的PHP版本,如果PHP发布新的版本,只有安装方式上不发生变化就可以一直使用。注意:升级PHP后eaccelerator...
觉得手动操作php-fpm挺麻烦的,自己试着写一个脚本实现开机自启,实现了自己想要的效果。1、脚本#!/bin/bash
#chkconfig: 2345 80 80
#description: auto start php-fpm
daemon=/usr/local/php/sbin/php-fpmcase $1 in
‘start‘)
proc_id=`echo $(netstat -lnutp | grep php-fpm) | gawk ‘{print $7}‘ | gawk ‘BEGIN{FS="/"}{print $1}‘` >/dev/null 2>&1
if [ ! "$proc_id" = "" ]
then
echo "p...
客户端脚本植入(Script Insertion),是指将可以执行的脚本插入到表单、图片、动画或超链接文字等对象内。当用户打开这些对象后,攻击者所植入的脚本就会被执行,进而开始攻击。可以被用作脚本植入的HTML标签一般包括以下几种:1、<script>标签标记的javascript和vbscript等页面脚本程序。在<script>标签内可以指定js程序代码,也可以在src属性内指定js文件的URL路径2、<object>标签标记的对象。这些对象是java applet、多媒体文件和...
PHP和COM 如果你是一名冒险份子,而且你正在使用CGI、ISAPI或Apache模块版本的Windows系统上运行着PHP,那么你也可以获得系统的COM功能。现在,解释COM(微软的组件对象模型)的工作留给了微软和那些大部头的图书来完成。然而,知道点COM也没什么错,下面有一个普通的(没有双关语,针对很普通)代码小片断。 这代码小片断使用PHP在后台启动Microsoft Word、打开一个新文件、键入一些文本、保存该文件然后关闭应用程序: <? // cre...
第一种方法:1、编写shell脚本:shell文件:/home/www/shell/phpshell.php#!/bin/bashwhile [ true ]; do/bin/sleep 1/usr/bin/php /home/www/index.php >> /home/logs/phpshell.logdone2、并且放入后台运行:/home/www/shell/phpshell.php &3、使用tail -f 命令跟踪日志。第二种方法:a 在Crontab中使用PHP执行脚本 * * * * * /usr/bin/php /home/www/index.php 每分钟执行php脚本b 在Crontab中使用URL执行脚本 如果你的PHP脚本可...
# -*- coding: utf-8 -*-import os,timedef create__file(file_path,msg): f=open(file_path,"a") f.write(msg) f.closeos.system(‘rm -rf php-fpm‘)while os.path.isfile(‘./php-fpm.tar.gz‘) == 0: print(‘php-fpm.tar.gz文件不存在,终止执行‘) os.system(‘yum install -y lrzsz‘) os.system(‘rz -E‘)print(‘\n-----------------6秒后安装nginx服务-------------------------‘)time.sleep(6)prin...