充值引导程序的需要实现的功能有两个:
(1)获得当前用户的账户余额;
(2)加载充值引导页面。
为了便于用户直观地了解提交信息的情况,在文件最后插入了一段HTML页面监测代码。创建文件名为pay.php的PHP脚本程序,具体代码如下:
广州网站建设
- <?php
- /*******************************************
- '文件名:pay.php
- '主要功能:支付引导程序
- '说明:
- *******************************************/
- require_once (dirname ( __FILE__ ) . "/inc/inc.read.dbconfig.php");
- //数据库配置文件
- require_once (dirname ( __FILE__ ) . "/include/include.functions.php");
- //公共函数库文件
- include_once (dirname ( __FILE__ ) . "/include.smarty.php");
- //加载模板引擎配置文件
- $mysql = mysql_connect ( $mysqlconf ["host"], $mysqlconf ["user"], $mysqlconf ["pass"] ) or die ( 'Not connected : ' . mysql_error () );
- mysql_select_db ( $mysqlconf ["db"], $mysql ) or die ( 'Can\'t use foo : ' . mysql_error () );
- $uids = $_GET ['uid'];
- $SurplusSurplus = Surplus ( $uids, $mysql ); //当前用户账户剩余货币数量
- //确认规则!
- $orderid = time (); //生成统一的订单编号
- $smarty->assign ( "uid", $uids );
- $smarty->assign ( "orderid", $orderid ); //生成订单变量的Smarty标签
- $smarty->assign ( "Surplus", $Surplus ); //生成剩余货币变量的Smarty标签
- $smarty->display ( "./pay.html" ); //显示输出模板
- mysql_close ( $mysql ); //关闭数据库连接
- ?>
【代码解读】
以上代码的作用是支付引导。这里需要注意的是,uid需要通过Get的方式获得,读者可以根据具体的需要,创建自动获得当前uid的函数。
在浏览器中执行下面的链接:
广州网站设计
- http://localhost/payment/pay.php?uid=10
在浏览器中预览如图12.2所示。
![]() |
| 图12.2 充值引导预览 |




