用php的c扩展编程调用 c程序的动态链接库
一. 首先做一个简单的so文件:
/**
* hello.c
* To compile, use following commands:
* gcc -O -c -fPIC -o hello.o hello.c
* gcc -shared -o libhello.so hello.o
*/
int hello_add(int a, int b)
{
return a + b;
}
然后将它编译成.so文件并放到系统中:
$ gcc -O -c -fPIC -o hello.o hello.c
$ gcc -shared -o libhello.so hello.o
$ su
# echo /usr/local/lib > /etc/ld.so.conf.d/local.conf
# cp libhello.so /usr/local/lib
# /sbin/ldconfig
二. 写段小程序来验证其正确性:
/**
* hellotest.c
* To compile, use following commands:
* gcc -o hellotest -lhello hellotest.c
*/
#include <stdio.h>
int main()
{
int a = 3, b = 4;
printf("%d + %d = %d\n", a, b, hello_add(a,b));
return 0;
}
编译并执行:
$ gcc -o hellotest -lhello hellotest.c
$ ./hellotest
3 + 4 = 7
三.
然后通过下面的命令建立一个名为 hello 的模块。
$ ./ext_skel --extname=hello
执行该命令之后它会提示你应当用什么命令来编译模块,可惜那是将模块集成到php内部的编译方法。如果要编译成可动态加载的 php_hello.so,方法要更为简单。
$ cd hello
首先编辑 config.m4 文件,去掉第16行和第18行
相关文档:
一.环境的安装
下载安装包,Google上搜索php+apache+sql的安装包并安装。
二.扩展编程
针对在PHP环境下掉用C编程(c程序编译的dll),主要有以下两种方式。
1.利用ATL构建DLL组件,然后再PHP里面直接调用,调用方法 ......
#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
FILE *fp, *fp2;
char buf[1024*300];
fp = fopen("in.txt", "rb");
fp2 = fopen("out.txt", "wb+");
fseek(fp, 0, SEEK_END);
int iLen ......
// 摘自:Wikipedia.org
C语言的标准文文件要求了一个平台移植C语言的时候至少要实现的一些功能和封装的集合,称为“标准库”,标准库的声明头部通过预处理器命令#include进行引用。
在C89标准中:
01. <assert.h>
02. <ctype.h>
&n ......
函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
& ......
对PHP安全方面的资料作了些收集和查阅,PHP注入首当其冲,一篇神秘小强的PHP万能密码写得不错,摘录:
说实话如果一个网站的前台都是注入漏洞,那么凭经验,万能密码进后台的几率基本上是百分之百。
可是有的人说对PHP的站如果是GPC魔术转换开启,就会对特殊符号转义,就彻底杜绝了PHP注入。其实说这话的人没有好好想过, ......