zoukankan      html  css  js  c++  java
  • 传值接值,php文件互联

    echo '<pre>';
    print_r($_POST);//接post传值
    print_r($_GET);//接get传值
    print_r($_REQUEST);///接post传值或者get传值
    print_r($_SERVER);
    超级链接传值用的是get方法 $get,$request
    1. <a href="ll.php?name=李四&age=20&psw=123">注册</a>
    get传值在标题栏显示账号密码不安全
    session 会话,只要是登陆,验证码用的比较多
    1.<?php
    session_start();
    $_SESSION['user']='admin';
    先执行admin
    2.session_start();//在当前网页的第一行开始
    if(!isset($_SESSION['user'])){
    echo '请去登陆';
    }else{
    echo '欢迎:'.$_SESSION['user'];
    }

    1. <?php
    2. session_start();
    3. if(isset($_POST['checkcode'])){
    4. if($_POST['checkcode']==''){
    5. echo '请填写验证码';
    6. }else if($_POST['checkcode']==$_SESSION['code']){
    7. echo '验证码输入正确';
    8. }else{
    9. echo '验证码有误';
    10. }
    11. }else{
    12. echo 'no';
    13. }
    验证验证码是否错误
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title></title>
    6. <meta name="keywords" content="关键字">
    7. <meta name="description" content="简介">
    8. <link rel="stylesheet" type="text/css" href="index.css">
    9. <script src=""></script>
    10. </head>
    11. <body>
    12. <form action="reg.php" method="post">
    13. 姓名: <input type="text" autofocus name="user"><br>
    14. 密码: <input type="password" name="psw"><br>
    15. 验证码:<input type="text" name="checkcode">
    16. <img src="inc/c.php"><br>
    17. <input type="submit" value="提交">
    18. </form>
    19. </body>
    20. </html>

    c.php
    <?php
    include 'i.php';
    check();
    i.php
    1. <?php
    2. function check($len=4){
    3. session_start();
    4. header('content-type:image/png');
    5. $fs = ['/a.ttf','/b.ttf','/f.ttf'];
    6. $font = dirname(__FILE__).$fs[mt_rand(0,1)];
    7. $w = 35*$len;
    8. $h = 50;
    9. $i = imagecreatetruecolor($w,$h);
    10. $c = imagecolorallocatealpha($i,0,0,0,127);
    11. //imagecolortransparent($i,$c);
    12. //imagefill($i,0,0,$c);
    13. imagefilledrectangle($i,0,0,$w,$h,gc($i,'ffffff',mt_rand(0,2)));
    14. $sss = '';
    15. for($j=0;$j<$len;$j++){
    16. $st = gs(1);
    17. $sss.=$st;
    18. imagettftext($i,mt_rand(15,25),mt_rand(-30,30),$j*35+10,mt_rand(28,38),gc($i),$font,$st);
    19. }
    20. $_SESSION['code'] = $sss;
    21. imagesetthickness($i,mt_rand(2,8));
    22. for($j=0;$j<mt_rand(5,10);$j++){
    23. imagefilledarc($i,mt_rand(0,$w),mt_rand(0,$h),mt_rand(0,$w),mt_rand(0,$h),mt_rand(0,360),mt_rand(0,360),gc($i,'rand',mt_rand(100,120)),IMG_ARC_NOFILL);
    24. }
    25. for($j=0;$j<10;$j++){
    26. imagettftext($i,mt_rand(10,15),mt_rand(-5,5),mt_rand(0,$w),mt_rand(0,$h),gc($i,'rand',mt_rand(100,120)),$font,gs(1));
    27. }
    28. imagepng($i);
    29. imagedestroy($i);
    30. }
    31. function gs($n=4){
    32. $s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    33. $t = '';
    34. for($i=0;$i<$n;$i++){
    35. $t.=substr($s,mt_rand(0,strlen($s)-1),1);
    36. }
    37. return $t;
    38. }
    39. /**
    40. * 生成缩略
    41. */
    42. function thumb($i,$f=false,$w=220,$h=0,$fn='s_'){
    43. $ii = getimagesize($i);
    44. if($ii[2]==2){
    45. if($ii[0]>$w){
    46. $src = imagecreatefromjpeg($i);
    47. $sw = $ii[0];
    48. $sh = $ii[1];
    49. $h = $h==0 ? $w/$sw*$sh : $h;
    50. //建立新的缩略图
    51. $dst = imagecreatetruecolor($w,$h);
    52. imagecopyresampled($dst,$src,0,0,0,0,$w,$h,$sw,$sh);
    53. if($f){
    54. imagejpeg($dst,$i);
    55. }else{
    56. $path = dirname($i).'/';
    57. $name = $fn.substr($i,strrpos($i,'/')+1);
    58. imagejpeg($dst,$path.$name);
    59. }
    60. imagedestroy($dst);
    61. imagedestroy($src);
    62. }
    63. }
    64. }
    65. /**
    66. * 功能:生成水银图标,水银图标文件在inc目录中 名称 logo.png
    67. */
    68. function logo($i,$p=5,$f=true,$fn='logo_'){
    69. $ii = getimagesize($i);
    70. if($ii[2]==2){
    71. if($ii[0]>300){
    72. $ni = imagecreatefromjpeg($i);
    73. $w = $ii[0];
    74. $h = $ii[1];
    75. //水银图标 logo.png 格式
    76. $logo = dirname(__FILE__).'/logo.png';
    77. $li = imagecreatefrompng($logo);
    78. $liw = imagesx($li);
    79. $lih = imagesy($li);
    80. $x = ($w-$liw)/2;
    81. $y = ($h-$lih)/2;
    82. $pad = 35;
    83. switch($p){
    84. case 1:
    85. $x = 0+$pad;
    86. $y = 0+$pad;
    87. break;
    88. case 2:
    89. $y = 0+$pad;
    90. break;
    91. case 3:
    92. $x = $w-$liw-$pad;
    93. $y = 0+$pad;
    94. break;
    95. case 4:
    96. $x = 0+$pad;
    97. break;
    98. case 6:
    99. $x = $w-$liw-$pad;
    100. break;
    101. case 7:
    102. $x = 0+$pad;
    103. $y = $h-$lih-$pad;
    104. break;
    105. case 8:
    106. $y = $h-$lih-$pad;
    107. break;
    108. case 9:
    109. $x = $w-$liw-$pad;
    110. $y = $h-$lih-$pad;
    111. break;
    112. }
    113. imagecopy($ni,$li,$x,$y,0,0,$liw,$lih);
    114. if($f){
    115. imagejpeg($ni,$i);
    116. }else{
    117. $path = dirname($i).'/';
    118. $name = $fn.substr($i,strrpos($i,'/')+1);
    119. imagejpeg($ni,$path.$name);
    120. }
    121. imagedestroy($ni);
    122. imagedestroy($li);
    123. }
    124. }
    125. }
    126. function txt($i,$s=30,$t='版权所有',$c='rand',$a=0,$p=5,$f=true,$fn='t_'){
    127. $font = dirname(__FILE__).'/f.ttf';
    128. $ii = getimagesize($i);
    129. if($ii[2]==2){
    130. if($ii[0]>300){
    131. $ni = imagecreatefromjpeg($i);
    132. $pos = imagettfbbox($s,0,$font,$t);
    133. $pad = 30;
    134. switch($p){
    135. case 1://左上角
    136. $x = 0-$pos[0]+$pad;
    137. $y = 0-$pos[7]+$pad;
    138. break;
    139. case 2://上边 水平中央
    140. $x = ($ii[0]-$pos[2])/2;
    141. $y = 0-$pos[7]+$pad;
    142. break;
    143. case 3:
    144. $x = $ii[0]-$pos[2]-$pad;
    145. $y = 0-$pos[7]+$pad;
    146. break;
    147. case 4:
    148. $x = 0-$pos[0]+$pad;
    149. $y = ($ii[1]-$pos[6])/2;
    150. break;
    151. case 5:
    152. $x = ($ii[0]-$pos[2])/2;
    153. $y = ($ii[1]-$pos[6])/2;
    154. break;
    155. case 6:
    156. $x = $ii[0]-$pos[2]-$pad;
    157. $y = ($ii[1]-$pos[6])/2;
    158. break;
    159. case 7:
    160. $x = 0-$pos[0]+$pad;
    161. $y = $ii[1]-$pos[6]-$pad;
    162. break;
    163. case 8:
    164. $x = ($ii[0]-$pos[2])/2;
    165. $y = $ii[1]-$pos[6]-$pad;
    166. break;
    167. case 9:
    168. $x = $ii[0]-$pos[2]-$pad;
    169. $y = $ii[1]-$pos[6]-$pad;
    170. break;
    171. }
    172. imagettftext($ni,$s,0,$x,$y,gc($ni,$c,$a),$font,$t);
    173. if($f){
    174. imagejpeg($ni,$i);
    175. }else{
    176. $path = dirname($i).'/';
    177. $name = $fn.substr($i,strrpos($i,'/')+1);
    178. imagejpeg($ni,$path.$name);
    179. }
    180. imagedestroy($ni);
    181. }
    182. }
    183. }
    184. function gc($i,$c='rand',$a=0){
    185. $color = '';
    186. switch($c){
    187. case 'white':
    188. $color = imagecolorallocatealpha($i,255,255,255,$a);
    189. break;
    190. case 'black':
    191. $color = imagecolorallocatealpha($i,0,0,0,$a);
    192. break;
    193. case 'red':
    194. $color = imagecolorallocatealpha($i,255,0,0,$a);
    195. break;
    196. case 'green':
    197. $color = imagecolorallocatealpha($i,0,255,0,$a);
    198. break;
    199. case 'rand':
    200. $color = imagecolorallocatealpha($i,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255),$a);
    201. break;
    202. default:
    203. $cc = str_split($c,2);
    204. $color = imagecolorallocatealpha($i,hexdec($cc[0]),hexdec($cc[1]),hexdec($cc[2]),$a);
    205. break;
    206. }
    207. return $color;
    208. }






  • 相关阅读:
    关于JDK和eclipse的安装和汉化
    关于Android SDK Manager更新速度慢的解决方法
    Navicat Premium 11破解补丁下载及安装方法
    win8.1下无法运行vc++6.0的解决方法
    在Editplus中配置java的(带包)编译(javac)和运行(java)的方法
    关于在Editplus中设置内容提示比如syso的快捷输出的方法
    关于win8/win8.1系统不能调节亮度的解决办法
    JDK的安装和Java环境变量配置
    关于classpath
    Genymotion模拟器的安装及常见问题解决方法
  • 原文地址:https://www.cnblogs.com/lsr111/p/4523576.html
Copyright © 2011-2022 走看看