ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingช่วยเพิ่มโค้ด php หน่อยครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ช่วยเพิ่มโค้ด php หน่อยครับ  (อ่าน 1119 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
MARINERdp
สมุนแก๊งเสียว
*

พลังน้ำใจ: 57
ออฟไลน์ ออฟไลน์

กระทู้: 587



ดูรายละเอียด เว็บไซต์
« เมื่อ: 28 กุมภาพันธ์ 2011, 04:14:48 »

เป็นโค้ดแสดงสถานะวิทยุนะครับ
คือเวลาวิทยุผมไม่ได้ออกอากาศ มันจะ eror แบบไม่หยุดจะทำยังไงให้มันหยุด
แล้วแสดงคำว่า offline


โค๊ด:
Warning: fsockopen() [function.fsockopen]: unable to connect to 68.168.100.60:34735 (Connection refused) in /mnt/r0305/d24/s16/b032eb9c/www/xxxxxx.com/radio/ShoutcastInfo.class.php on line 109

Error: Connection refused (111)
นี่โค้ดครับ
โค๊ด:
<?php
/***************************************************************************
 *                            ShoutcastInfo Class
 *                            -------------------
 *   begin                : Wednesday, Aug 18, 2004 - 4:12
 *   copyright            : (C) 2004 MC Breit
 *   email                : [email protected] - MCB.CC - Free and Open Sources
 *   last modified        : 18/08/04 - 06:26 - MC Breit
 *   version              : 0.0.2
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

//
// Begin ShoutcastInfo class.
//

class ShoutcastInfo
{

  
//
  // Begin of class variables
  //

  /*****
  * @var $sock
  * contains the socket handler.
  */
  
var $sock FALSE;
  
  
/*****
  * @var $error
  * saves errorstr and numbers as array(no,str)
  */
  
var $error = array(NULLNULL);
  
  
/*****
  * @var $host
  * contains the hostname for shoutcast server
  */
  
var $hostname NULL;
  
  
/*****
  * @var $port
  * contains the port used for connection
  */
  
var $port NULL;
  
  
/*****
  * @var $timeout
  * the timeout for connection
  */
  
var $timeout NULL;
  
  
/*****
  * @var $parsed
  * is true when datas where parsed
  */
  
var $parsed FALSE;
  
  
/****
  * @var $datas
  * contains the unparsed datas
  */
  
var $datas NULL;
  
  
/*****
  * @var $pdatas
  * assitioative array of parsed datas
  */
  
var $pdatas NULL;
  
  
//
  // Begin of class functions
  //
  
  /*****
  * object ShoutcastInfo(string hostname [, int port [, int timeout])
  * Crates an new Shoutcast Object. (Is the Class Creator)
  */
  
function ShoutcastInfo($hostname$port=8888$timeout=30)
  {
    
$this->hostname $hostname;
    
$this->port $port;
    
$this->timeout $timeout;
  } 
// ShoutcastInfo()
  
  //
  // Begin of socket and connection functions
  //
  
  /*****
  * bool connect( void )
  * creates server connection, returns true on success, else retruns false.
  */
  
function connect()
  {
    if( !
$this->sock )
    {
      
//Connect
      
$this->sock fsockopen($this->hostname$this->port$this->error[0] , $this->error[1], $this->timeout);
    }
    
    
//Check connection
    
if( $this->sock )
    {
      return 
TRUE;
    }
    else
    {
      return 
FALSE;
    }
  } 
// connect()
  
  /*****
  * bool close( void )
  * closes current connection
  */
  
function close()
  {
    if( 
$this->sock )
    {
      
fclose($this->sock);
    }
  } 
// close()
  
  /*****
  * bool refresh( void )
  * closes connection and opens it again to get new datas.
  * parsed datas will not replaced, but parsing will be
  * able again.
  */
  
function refresh()
  {
    
$this->close();
    
$this->sock NULL;
    if( !
$this->connect() )
    {
      return 
FALSE;
    }
    
$this->parsed FALSE;
    
$this->send();
    return 
TRUE;
  } 
// refresh()
  
  /*****
  * void send( void )
  * Sends http header and recives datas from server
  */
  
function send()
  {
    if( 
$this->sock )
    {
      
//Send HTTP Header
      
fputs($this->sock"GET / HTTP/1.0\r\n"
                        
."Host: 127.0.0.1\r\n"
                        
."User-Agent: Mozilla/4.0 (compatible; ShoutCastInfoClass/0.0.2; ".PHP_OS.")\r\n"
                        
."\r\n"
           
);
           
      
//Get datas
      
$this->datas NULL;
      while( !
feof($this->sock) )
      {
          
$this->datas .= fgets($this->sock128);
      }
    }
  } 
// send()
  
  /*****
  * mixed error( [bool return])
  * if return is true it will return a error message,
  * else it will print it out (HTML Formatted!).
  */
  
function error($return=FALSE)
  {
    if( 
$return == FALSE )
    {
      print 
"<br><b>Error:</b> {$this->error[1]} (<i>{$this->error[0]}</i>)<br>";
      return;
    }
    return 
"{$this->error[1]} ({$this->error[0]})";
  }
  
  
//
  // Begin of public functions
  //
  
  /*****
  * bool get_stat( void )
  * Checks that stream will be up and private/public. 
  */
  
function get_stat()
  {
    if( 
strstr($this->datas'Server is currently up and') )
    {
      
$this->pdatas['status'] = 1;
      return 
TRUE;
    }
    else
    {
      
$this->pdatas['status'] = 0;
      return 
FALSE;
    }
  } 
// get_stat()
  
  /*****
  * integer get_listener( void )
  * returns and resets the number of accutal listener.
  */
  
function get_listener()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['listener'] = 0;
      return 
0;
    }
    
    
$this->pdatas['listener_max'] = explode('kbps with <B>'$this->datas);
    
$this->pdatas['listener'] = explode(' of '$this->pdatas['listener_max'][1]);
    
$this->pdatas['listener_max'] = $this->pdatas['listener'][1];
    
$this->pdatas['listener'] = $this->pdatas['listener'][0];
    
$this->pdatas['listener_max'] = explode(' l'$this->pdatas['listener_max']);
    
$this->pdatas['listener_max'] = $this->pdatas['listener_max'][0];
    
    return 
$this->pdatas['listener'];
  } 
// get_listener()
  
  /*****
  * integer get_peak( void )
  * returns the listener peak from stream and resets it.
  */
  
function get_peak()
  {
    
$this->pdatas['peak'] = $this->_extract_datas('Listener Peak: </font></td><td><font class=default><b>');
    return 
$this->pdatas['peak'];
  } 
// get_peak()
  
  /*****
  * string get_title( void )
  * returns and resetts the actual moderator/dj/stream_title at stream.
  */
  
function get_title()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['title'] = FALSE;
      return 
FALSE;
    }
    
    
$this->pdatas['title'] = $this->_extract_datas('Stream Title: </font></td><td><font class=default><b>');
    return 
$this->pdatas['title'];
  } 
// get_title()
  
  /*****
  * string get_content_type( void )
  * returns and resetts the actual ContentType at stream.
  */
  
function get_content_type()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['content_type'] = FALSE;
      return 
FALSE;
    }
  
    
$this->pdatas['content_type'] = $this->_extract_datas('Content Type: </font></td><td><font class=default><b>');
    return 
$this->pdatas['content_type'];
  } 
// get_content_type()
  
  /*****
  * string get_genre( void )
  * returns and resetts the actual Stream Genre.
  */
  
function get_genre()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['genre'] = FALSE;
      return 
FALSE;
    }
  
    
$this->pdatas['genre'] = $this->_extract_datas('Stream Genre: </font></td><td><font class=default><b>');
    return 
$this->pdatas['genre'];
  } 
// get_genre()
  
  /*****
  * string get_url( void )
  * returns and resetts the actual Stream URL.
  */
  
function get_url()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['url'] = 'none';
      return 
'none';
    }
  
    
$this->pdatas['url'] = $this->_extract_datas('Stream URL: </font></td><td><font class=default><b><a href="''"');
    return 
$this->pdatas['url'];
  } 
// get_url()
  
  /*****
  * string get_icq( void )
  * returns and resetts the actual Stream ICQ.
  */
  
function get_icq()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['icq'] = FALSE;
      return 
FALSE;
    }
  
    
$this->pdatas['icq'] = $this->_extract_datas('ICQ: </font></td><td><font class=default><b><a href="http://wwp.icq.com/scripts/contact.dll?msgto=''"');
    
//ICQ is aviable?
    
$this->pdatas['icq'] = ( $this->pdatas['icq'] == 'NA' ) ? FALSE $this->pdatas['icq'];
    return 
$this->pdatas['icq'];
  } 
// get_icq()
  
  /*****
  * string get_aim( void )
  * returns and resetts the actual Stream AIM.
  */
  
function get_aim()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['aim'] = FALSE;
      return 
FALSE;
    }
  
    
$this->pdatas['aim'] = $this->_extract_datas('AIM: </font></td><td><font class=default><b><a href="aim:goim?screenname=''"');
    
//AIM is aviable?
    
$this->pdatas['aim'] = ( $this->pdatas['aim'] == 'NA' ) ? FALSE $this->pdatas['aim'];
    return 
$this->pdatas['aim'];
  } 
// get_aim()
  
  /*****
  * string get_irc( void )
  * returns and resetts the actual Stream IRC.
  * Note: This often is not a valid form of URL!
  */
  
function get_irc()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['irc'] = FALSE;
      return 
FALSE;
    }
  
    
$this->pdatas['irc'] = $this->_extract_datas('Stream IRC: </font></td><td><font class=default><b><a href="');
    
$this->pdatas['irc'] = strstr($this->pdatas['irc'], '">');
    
$this->pdatas['irc'] = substr($this->pdatas['irc'], 2);
    return 
$this->pdatas['irc'];
    
  } 
// get_irc()
  
  /*****
  * string get_track( void )
  * returns and resetts the current track informations.
  */
  
function get_track()
  {
    
//Is stream up?
    
if( $this->pdatas['status'] == )
    {
      
$this->pdatas['track'] = FALSE;
      return 
FALSE;
    }
  
    
$this->pdatas['track'] = $this->_extract_datas('Current Song: </font></td><td><font class=default><b>');
    return 
$this->pdatas['track'];
    
  } 
// get_track()
  
  /*****
  * array parse( void )
  * get all the items aviable and return an assoc array.
  * Note: Use this only if you need ALL the informations!
  */
  
function parse()
  {
    if( 
$this->parsed != TRUE )
    {
      
//get all single infos
      
$this->get_stat();
      
$this->get_listener();
      
$this->get_peak();
      
$this->get_title();
      
$this->get_content_type();
      
$this->get_genre();
      
$this->get_url();
      
$this->get_icq();
      
$this->get_aim();
      
$this->get_irc();
      
$this->get_track();
      
//set parsed stat
      
$this->parsed TRUE;
    }
    return 
$this->pdatas;
    
  } 
// parse()
  
  /*****
  * mixed get_parsed_value( string key )
  * Sucht aus dem geparsten array einen wert herraus und gibt ihn zur&#38;#63685;ck
  * wenn er noch nicht gesetzt ist wird NULL zur&#38;#63685;ckgegeben.
  */
  
function get_parsed_value($key)
  {
    return ( isset(
$this->pdatas[$key]) ) ? $this->pdatas[$key] : FALSE;
    
  } 
// get_parsed_value()
  
  //
  // Begin private functions
  //
  
  /*****
  * private mixed _extract_datas(string match_str [, string ending])
  * extracts and returns datas after an match_string and before net html tag or ending.
  */
  
function _extract_datas($match_str$ending='<')
  {
    
$datas strstr($this->datas$match_str);
    
//remove match_str because strstr starts before..
    
$datas str_replace($match_str''$datas);
    
//split text after ending mark and throw all away isnt needed.
    
$datas explode($ending$datas);
    return 
$datas[0];
    
  } 
// _extract_datas()

// ShoutcastInfo class

//
// Thats it folks!
//

?>



อีกคำถามนะครับ

เวลาเอาไปใช้งานตั้ง refresh ยังไงครับ

ขอบคุณนะครับมือใหม่เรื่อง php จริงๆ อยากรู้ wanwan017
« แก้ไขครั้งสุดท้าย: 28 กุมภาพันธ์ 2011, 04:24:38 โดย MARINERdp » บันทึกการเข้า

aummua
คนรักเสียว
*

พลังน้ำใจ: 15
ออฟไลน์ ออฟไลน์

กระทู้: 106



ดูรายละเอียด
« ตอบ #1 เมื่อ: 28 กุมภาพันธ์ 2011, 04:31:00 »

ขอดู โค้ด ที่เอาไปใช้งานอ่ะคับ อันนี้เห็นแต่ class
บันทึกการเข้า
MARINERdp
สมุนแก๊งเสียว
*

พลังน้ำใจ: 57
ออฟไลน์ ออฟไลน์

กระทู้: 587



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 28 กุมภาพันธ์ 2011, 04:33:06 »

โค๊ด:
<?php
$radiohost 
="68.168.100.60"// IP ¢Í§ server 
$port ="34735" // Port 

include_once('ShoutcastInfo.class.php'); 
$scs = &new ShoutcastInfo("$radiohost","$port");

if( !
$scs->connect() )
{
  
$scs->error();
  
$error TRUE;
}

if( 
$error != TRUE )
{
  
$scs->send();
  if( !
$scs->get_stat() )
  {
  }
  else 
//If server is online..
  
{
     } 
  
$scs->close();  



$radioport$port 
$radioofflinemsg='<FONT SIZE=2 ><CENTER>¢³Ð¹ÕéäÁèä´éÍ͹äŹì</CENTER></FONT>'// ¢éͤÇÒÁáÊ´§àÁ×èÍäÁèÁÕ´ÕਨѴà¾Å§
$radiopassword=$password 

$fp = @fsockopen($radiohost,$port);

fputs($fp"GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");

  while(!
feof($fp)){
    
$info fgets($fp);
  }

fclose($fp);

$info str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>'""$info);
$info str_replace('</body></html>'""$info);
$stats explode(','$info7);
$bitrate = (int) $stats[5];

$config = @file_get_contents($configpath);
$config preg_replace('/\r\n|\r/'"\n"$config);
$configline explode("\n"$config);

  for(
$i=0$i<count($configline); $i++){
    if(
strpos($configline[$i], "AdminPassword=") !== false){
      global 
$pass;
      
$pass substr($configline[$i], strpos($configline[$i], "=")+1);
    }
  }


?>



¡ÓÅѧà»Ô´à¾Å§ : <?=$scs->get_track()?><BR>
¨Ó¹Ç¹¤¹¿Ñ§ : <?=$scs->get_listener()?> ¤¹ <BR>
Bitrate : <?=$bitrate?> kbps<BR>
DJ : <?=$scs->get_title()?>
ขอบคุณครับ  wanwan017
บันทึกการเข้า

aummua
คนรักเสียว
*

พลังน้ำใจ: 15
ออฟไลน์ ออฟไลน์

กระทู้: 106



ดูรายละเอียด
« ตอบ #3 เมื่อ: 28 กุมภาพันธ์ 2011, 04:42:12 »

รู้สึกว่าท่าน จะ include class ไปใช้งานผิดนิดหน่อยนะ ลองเขียนแบบนี้ดู

<?php
$radiohost ="68.168.100.60"; // IP
$port ="34735" ; // Port

include_once('ShoutcastInfo.class.php');
$scs = &new ShoutcastInfo( $radiohost, $port);

if( !$scs->connect() )
{
  $scs->error();
  $error = TRUE;
}

if( $error != TRUE )
{
  $scs->send();
  if( !$scs->get_stat() )
  {
     //ถ้าไ่ม่มีผู้จัดรายการ
     echo 'Offline !';
  }
  else
  {
     //ถ้าเปิดวิทยุปกติ

     echo 'ชื่อเพลง : ', $scs->get_track() , '<br>';
     echo 'ผู้ฟัง : ', $scs->get_listener(), '<br>';
     echo 'ผู้จัด : ', $scs->get_title(), '<br>';
  }
  $scs->close(); 
}
?>
บันทึกการเข้า
MARINERdp
สมุนแก๊งเสียว
*

พลังน้ำใจ: 57
ออฟไลน์ ออฟไลน์

กระทู้: 587



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 28 กุมภาพันธ์ 2011, 04:52:32 »

+ ขอบคุณครับ

แล้วถ้าจะให้มันอัพเดทละครับ
ทั่วไปเขาตั้ง refresh กันเท่าไร
บันทึกการเข้า

MARINERdp
สมุนแก๊งเสียว
*

พลังน้ำใจ: 57
ออฟไลน์ ออฟไลน์

กระทู้: 587



ดูรายละเอียด เว็บไซต์
« ตอบ #5 เมื่อ: 28 กุมภาพันธ์ 2011, 05:14:44 »

ผมเพิ่ม
โค๊ด:
 echo "<meta http-equiv='refresh' content='1';url=index.php'>" ;

ไม่เห็นมันจะเปลี่ยนเลย หรือผิดตรงไหน wanwan023
บันทึกการเข้า

aummua
คนรักเสียว
*

พลังน้ำใจ: 15
ออฟไลน์ ออฟไลน์

กระทู้: 106



ดูรายละเอียด
« ตอบ #6 เมื่อ: 28 กุมภาพันธ์ 2011, 05:19:56 »

ผมเพิ่ม
โค๊ด:
 echo "<meta http-equiv='refresh' content='1';url=index.php'>" ;

ไม่เห็นมันจะเปลี่ยนเลย หรือผิดตรงไหน wanwan023


ก็ สร้างไฟล์ ขึ้นมาไฟล์นึง แล้ว เอาโค้ด meta refresh ไปใส่ในไฟล์นั้นครับ

โค้ดนี้
echo "<meta http-equiv='refresh' content='1';url=index.php'>" ;

แก้เป็น
echo "<meta http-equiv='refresh' content='1;url=index.php'>" ;


ส่วนใหญ่ ตั้งไว้ซัก 30 วินาที ก็ได้ครับ Cheesy
« แก้ไขครั้งสุดท้าย: 28 กุมภาพันธ์ 2011, 05:30:06 โดย aummua » บันทึกการเข้า
MARINERdp
สมุนแก๊งเสียว
*

พลังน้ำใจ: 57
ออฟไลน์ ออฟไลน์

กระทู้: 587



ดูรายละเอียด เว็บไซต์
« ตอบ #7 เมื่อ: 28 กุมภาพันธ์ 2011, 11:41:48 »

ขอหน้า index หน่อยได้ไหมครับผมไม่รู้ว่าแทรกตรงไหน Lips Sealed
บันทึกการเข้า

zenithsoul
Verified Seller
ก๊วนเสียว
*

พลังน้ำใจ: 56
ออฟไลน์ ออฟไลน์

กระทู้: 293



ดูรายละเอียด
« ตอบ #8 เมื่อ: 28 กุมภาพันธ์ 2011, 18:24:39 »

Refresh Data ผมแนะนำใช้ aJax ผสมด้วยครับ

จะได้รู้สึกเหมือน RealTime Get ข้อมุลมาเป็นช่วง ๆ  wanwan019
บันทึกการเข้า
MARINERdp
สมุนแก๊งเสียว
*

พลังน้ำใจ: 57
ออฟไลน์ ออฟไลน์

กระทู้: 587



ดูรายละเอียด เว็บไซต์
« ตอบ #9 เมื่อ: 28 กุมภาพันธ์ 2011, 19:03:27 »

Refresh Data ผมแนะนำใช้ aJax ผสมด้วยครับ

จะได้รู้สึกเหมือน RealTime Get ข้อมุลมาเป็นช่วง ๆ  wanwan019

ทำไงอ่ะครับ หาข้อมูลได้ที่ไหน  Cry
บันทึกการเข้า

หน้า: [1]   ขึ้นบน
พิมพ์