网站地图    收藏   

主页 > php专栏 > 流程控制语句 >

cookie 函数 session mail 数据库连接 xml - php会话

来源:自学PHP网    时间:2014-11-27 22:01 作者: 阅读:

[导读] ?php 写cookiesetcookie(user,wang70937,time()+60); sessionsession_start();if(isset($_session[ 39;views 39;]))$_session[ 39;views 39;]=$_session[ 39;views 39;]+1;else$_sess...

cookie 函数 session mail 数据库连接 xml

  1. <?php 
  2. //写cookie 
  3. setcookie("user""wang70937", time()+60); 
  4. //session 
  5. session_start(); 
  6.  
  7. if(isset($_session['views'])) 
  8.   $_session['views']=$_session['views']+1; 
  9.  
  10. else 
  11.   $_session['views']=1; 
  12. echo "session: views="$_session['views']."<br />"
  13. ?> 
  14.  
  15. <script > 
  16.     function show(){ 
  17.         alert("asdf"); 
  18.     } 
  19. </script> 
  20.  
  21. <html> 
  22.     <title>php测试页面 </title> 
  23.     <head><script src="clienthint.js"></script></head> 
  24.     <body> 
  25.         <?php 
  26.             //输出 
  27.             echo "<br />"."[******输出******]"."<br />"
  28.             echo "hello world!"."<br />"
  29.             $a = "php"
  30.             $b = "language"
  31.             echo $a." ".$b."<br />"
  32.              
  33.             //数组 
  34.             echo "<br />"."[******数组******]"."<br />"
  35.             $arr = array("abcde""fghijk""lmnopq"); 
  36.             foreach($arr as $value
  37.             { 
  38.                 echo $value."<br />"
  39.             } 
  40.              
  41.             //函数 
  42.             echo "<br />"."[******函数******]"."<br />"
  43.             function funa($a$b){ 
  44.                 echo "函数参数:".$a.", ".$b
  45.                 return "ret_value"
  46.             } 
  47.             $ret = funa(123, "param"); 
  48.             echo "函数返回值:".$ret."<br />"
  49.              
  50.          
  51.             echo "<br />"."[******表单******]"."<br />"
  52.         ?> 
  53.             <form action="form.php" method="post"
  54.             name: <input type="text" name="name" /> 
  55.             age: <input type="text" name="age" /> 
  56.             <input type="submit" /> 
  57.             </form> 
  58.              
  59.         <?php   echo "<br />"
  60.              
  61.             echo "<br />"."[******上传文件******]"."<br />"
  62.         ?>   
  63.             <form action="upload_file.php" method="post" 
  64.             enctype="multipart/form-data"
  65.             <label for="file">filename:</label> 
  66.             <input type="file" name="file" id="file" />  
  67.             <br /> 
  68.             <input type="submit" name="submit" value="submit" /> 
  69.             </form> 
  70.          
  71.         <?php    
  72.             //session 
  73.             echo "<br />"."[******session******]"."<br />"
  74.              
  75.             //retrieve session data 
  76.             echo "pageviews="$_session['views']; 
  77.         ?> 
  78.             <br />   
  79.              
  80.             <!-- //删除session --> 
  81.         <?php 
  82.             //echo "<br />"."[******删除session******]"."<br />"; 
  83.             // session_destroy();  
  84.         ?> 
  85.  
  86.         <?php 
  87.             //发送邮件 
  88.             echo "<br />"."[******发送邮件******]"."<br />"
  89.              
  90.             $to = "wang70937@163.com"
  91.             $subject = "test mail"
  92.             $message = "hello! this is a simple email message."
  93.             $from = "wang70937@gmail.com"
  94.             $headers = "from: $from"
  95.             mail($to,$subject,$message,$headers); 
  96.             echo "mail sent."."<br />"
  97.         ?> 
  98.  
  99.         <?php 
  100.             //mysql教程数据库教程 
  101.             echo "<br />"."[******mysql数据库******]"."<br />"
  102.             $con = mysql_connect("localhost","root","1"); 
  103.             if (!$con
  104.         { 
  105.             die('could not connect: ' . mysql_error()); 
  106.         } 
  107.             else 
  108.                 echo "连接mysql成功!"."<br />"
  109.             mysql_select_db("bbs"$con); 
  110.             mysql_query("set names gbk"); 
  111.             //show tables 
  112.             $tablecount = mysql_query("show tables"); 
  113.             while($table = mysql_fetch_array($tablecount)) 
  114.             { 
  115.                 //表名 
  116.                 $tablename = $table[0]; 
  117.                 $sql = "select * from ".$tablename
  118.                 $result = mysql_query($sql); 
  119.                  
  120.                 echo "<br />表:[".$tablename."]<br />"
  121.                 //表的字段个数     
  122.                 $filedcount = mysql_num_fields($result); 
  123.                 //记录条数 
  124.                 $recordcount = mysql_num_rows($result); 
  125.                  
  126.                 echo "sql[".$sql."] 记录条数:".$recordcount."<br />"
  127.                  
  128.                 if($filedcount > 0 ) 
  129.                 { 
  130.                     echo "<table border='1'>; 
  131.                     <tr> 
  132.                     <th>记录序号</th>"; 
  133.                     for($index=0; $index<$filedcount$index++) 
  134.                     { 
  135.                         //字段名 
  136.                         $filedname = mysql_fetch_field($result); 
  137.                         echo "<th>$filedname->name</th>"
  138.                     } 
  139.                     echo "</tr>"
  140.                     $no = 0; 
  141.                     while($row = mysql_fetch_array($result)) 
  142.                 { 
  143.                     $no = $no + 1; 
  144.                     echo "<tr>"
  145.                     echo "<td>" . $no . "</td>"
  146.                     for($index=0; $index<$filedcount$index++) 
  147.                     { 
  148.                         echo "<td>" . $row[$index] . "</td>"
  149.                     } 
  150.                     echo "</tr>"
  151.                 } 
  152.                     echo "</table>"
  153.                  
  154.                 } 
  155.             } 
  156.              
  157.              
  158.  
  159.  
  160.             mysql_close($con); 
  161.         ?> 
  162.  
  163.             <?php 
  164.             //xml解析 
  165.             echo "<br />"."********xml解析********"."<br />"
  166.              
  167.             /*$xmldoc = new domdocument(); 
  168.             $xmldoc->load("note.xml"); 
  169.  
  170.             $x = $xmldoc->documentelement; 
  171.             foreach ($x->childnodes as $item) 
  172.         { 
  173.                 print $item->nodename . " = " . $item->nodevalue . "<br />"; 
  174.         }*/ 
  175.         $xml = simplexml_load_file("note.xml"); 
  176.  
  177.             echo $xml->getname() . "<br />"
  178.  
  179.             foreach($xml->children() as $child
  180.         { 
  181.             echo $child->getname() . ": " . $child . "<br />"
  182.         } 
  183.             ?> 
  184.              
  185.             <?php 
  186.             //ajax 
  187.             echo "<br />"."*******ajax*******"."<br />"
  188.             ?> 
  189.             <form>  
  190.             first name: 
  191.             <input type="text" id="txt1" 
  192.             //onkeyup="showhint(this.value)" 
  193.             onkeyup="show()"
  194.             </form> 
  195.             <p>suggestions: <span id="txthint"></span></p> 
  196.     </body> 
  197. </html> 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论