Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Cum declari o variabila care nu s...

Schimbare certificat de inmatricu...

Poligon auto București

nelamurire legata de pret la mode...
 Hotel cu restaurant si Demipensiu...

Croaziera in Mediterana de Vest 1...

Copilot are pica pe Vladimir Putin

MicroSoft Edge: Cum pun Google in...
 Dashcam

Mini server - VMware

betano.ro

Poveste fara sfarșit
 I-auziti voi! - nu vor romani...

Colon iritabil

Perioada de gratie inexistenta

Cel mai ieftin TV LED mic
 

variabila IP

- - - - -
  • Please log in to reply
16 replies to this topic

#1
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
salut. am si eu o problema daca ma poate ajuta cineva...am  un script pentru un guestbook la care nu stiu ce sa adaug ca atunci cand cineva lasa mesaj...acolo unde apare data la care a fost postat mesajul, sa apara si ip-ul de la care a fost postat acest mesaj...Acesta este scriptul:

<?php
/**
* Max
*
* This is the Max's Guestbook business logic class.
* For more details please read the readme.txt
*/
?>
<?php
class maxGuestbook{
   var $messageDir = 'messages';
   var $dateFormat = 'Y-m-d g:i:s A';
   var $itemsPerPage = 5;
   var $messageList;
  
function processGuestbook(){
   if (isset($_POST['submit'])) {
      $this->insertMessage();
   }
   $page = isset($_GET['page']) ? $_GET['page'] : 1;
  
   $this->displayGuestbook($page);
}
  
function getMessageList(){

   $this->messageList = array();
  
// Open the actual directory
if ($handle = @opendir($this->messageDir)) {
// Read all file from the actual directory
while ($file = readdir($handle))  {
    if (!is_dir($file)) {
       $this->messageList[] = $file;
       }
}
}

rsort($this->messageList);

return $this->messageList;
}  

function displayGuestbook($page=1){
      $list = $this->getMessageList();
      //echo "<center><a href='add.php'>Leave a message</a></center>";
      echo "<table class='newsList'>";
      
      //Get start point and end point
      $startItem = ($page-1)*$this->itemsPerPage;
      if (($startItem + $this->itemsPerPage) > sizeof($list)) $endItem = sizeof($list);
      else $endItem = $startItem + $this->itemsPerPage;
      
      for ($i=$startItem;$i<$endItem;$i++){
         //foreach ($list as $value) {
         $value = $list[$i];
       $data = file($this->messageDir.DIRECTORY_SEPARATOR.$value);
       $name  = trim($data[0]);
       $email = trim($data[1]);
         $submitDate = trim($data[2]);
         unset ($data['0']);
         unset ($data['1']);
         unset ($data['2']);
      
         $content = "";
         foreach ($data as $value) {
            $content .= $value;
         }
      
       echo "<tr><th align='left'><a href=\"mailto:$email\">$name</a></th>
                 <th class='right'>$submitDate</th></tr>";
       echo "<tr><td colspan='2'>".nl2br(htmlspecialchars($content))."<br/></td></tr>";
      }
      echo "</table>";
      if (sizeof($list) == 0){
         echo "<center><p>No messages at the moment!</p><p>&nbsp;</p></center>";
      }
      // Create pagination
      if (sizeof($list) > $this->itemsPerPage){
         echo "<div id=\"navigation\">";
         if ($startItem == 0) {
            if ($endItem < sizeof($list)){
               echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Pagina urmatoare &raquo;</a></div>";
            } else {
               // Nothing to display
            }
         } else {
            if ($endItem < sizeof($list)){
               echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Pagina anterioara</a></div>";
               echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Pagina urmatoare &raquo;</a></div>";
            } else {
               echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Pagina anterioara</a></div>";
            }
         }
        
         echo "<br/></div><br/>";
      }
      echo "<hr />";
      $this->displayAddForm();
}

function displayAddForm(){
?>  
  <form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Nume:<br/>
    <input type="text" name="Nume" size="30"/><br/><br/>
    Email:<br/>
    <input type="text" name="email" size="30"/><br/><br/>
    Mesajul tau:<br/>
    <textarea name="message" rows="7" cols="49"></textarea><br/>
    <center><input type="submit" name="submit" value="Trimite" /></center>
  </form>
  
<?php  
}

function insertMessage(){
   $name   = isset($_POST['name']) ? $_POST['name'] : 'Anonim';
   $email  = isset($_POST['email']) ? $_POST['email'] : '';
   $submitDate  = date($this->dateFormat);
   $content = isset($_POST['message']) ? $_POST['message'] : '';
  
   if (trim($name) == '') $name = 'Anonim';
   if (strlen($content)<5) {
      exit();
   }
  
   $filename = date('YmdHis');
   if (!file_exists($this->messageDir)){
      mkdir($this->messageDir);
   }
   $f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");        
   fwrite($f,$name."\n");
   fwrite($f,$email."\n");
   fwrite($f,$submitDate."\n");
   fwrite($f,$content."\n");
   fclose($f);
  
}
}
?>

#2
w3room

w3room

    Senior Member

  • Grup: Senior Members
  • Posts: 2,085
  • Înscris: 22.09.2010
Salut.

Înlocuiește codul după formular, cu ăsta :

<?php 
}

function insertMessage(){
$name = isset($_POST['name']) ? $_POST['name'] : 'Anonim';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$submitDate = date($this->dateFormat);
$content = isset($_POST['message']) ? $_POST['message'] : '';

if (trim($name) == '') $name = 'Anonim';
if (strlen($content)<5) {
exit();
}

$filename = date('YmdHis');
if (!file_exists($this->messageDir)){
mkdir($this->messageDir);
}
$f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+"); 
fwrite($f,$name."\n");
fwrite($f,$email."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$content."\n");
fwrite($f,$_SERVER['REMOTE_ADDR']."\n");
fclose($f);

}
}
?>



#3
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
merge...multumesc mult!

Edited by yo_suporter, 07 January 2012 - 21:20.


#4
w3room

w3room

    Senior Member

  • Grup: Senior Members
  • Posts: 2,085
  • Înscris: 22.09.2010

View Postyo_suporter, on 7th January 2012, 21:14, said:

daca fac modificarea asta...nu imi mai apare nimic...adica nu mi se mai deschide guestbookul... :(
Da' cu codul tău care l-ai postat în primul post se deschide ?

Caută partea asta de cod :

$f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+"); 
fwrite($f,$name."\n");
fwrite($f,$email."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$content."\n");
fclose($f);

Și înlocuiește-o cu asta :

$f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+"); 
fwrite($f,$name."\n");
fwrite($f,$email."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$content."\n");
fwrite($f,$_SERVER['REMOTE_ADDR']."\n");
fclose($f);


#5
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
gata...merge. multumesc mult! :)

Edited by yo_suporter, 07 January 2012 - 21:35.


#6
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
si inca ceva... ce trebuie sa adaug la functia asta fwrite($f,$_SERVER['REMOTE_ADDR']."\n"); ...ca ip-ul sa imi apara scris in guest book intr-o anumita culoare pusa de mine...si sa imi apara sub forma: IP: xxxxxxxxxx multumesc.

Edited by yo_suporter, 09 January 2012 - 04:05.


#7
w3room

w3room

    Senior Member

  • Grup: Senior Members
  • Posts: 2,085
  • Înscris: 22.09.2010
fwrite($f,"<span style=color:red>IP : ".$_SERVER['REMOTE_ADDR']."</span>");

Edited by w3room, 09 January 2012 - 11:28.


#8
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
nu se schimba culoarea...imi da eroare...imi apare asa: <span=color:red>IP : xxxxxxxx</span>

#9
w3room

w3room

    Senior Member

  • Grup: Senior Members
  • Posts: 2,085
  • Înscris: 22.09.2010
Ia vezi așa :

<?php
/**
 * Max's Guestbook
 * 
 * This is the Max's Guestbook business logic class. 
 * For more details please read the readme.txt
 */
?>
<?php
class maxGuestbook{
   var $messageDir = 'messages';
   var $dateFormat = 'Y-m-d g:i:s A';
   var $itemsPerPage = 5;
   var $messageList;
   
function processGuestbook(){
   if (isset($_POST['submit'])) {
	  $this->insertMessage();
   }
   $page = isset($_GET['page']) ? $_GET['page'] : 1;
   
   $this->displayGuestbook($page);
}
   
function getMessageList(){
	
   $this->messageList = array();
   
	// Open the actual directory
	if ($handle = @opendir($this->messageDir)) {
		// Read all file from the actual directory
		while ($file = readdir($handle))  {
			if (!is_dir($file)) {
			   $this->messageList[] = $file;
		  }
		}
	}	
	
	rsort($this->messageList);
	
	return $this->messageList;
}   

function displayGuestbook($page=1){
	  $list = $this->getMessageList();
	  //echo "<center><a href='add.php'>Leave a message</a></center>";
	  echo "<table class='newsList'>";
	  
	  //Get start point and end point
	  $startItem = ($page-1)*$this->itemsPerPage;
	  if (($startItem + $this->itemsPerPage) > sizeof($list)) $endItem = sizeof($list);
	  else $endItem = $startItem + $this->itemsPerPage; 
	  
	  for ($i=$startItem;$i<$endItem;$i++){
		 //foreach ($list as $value) {
		 $value = $list[$i];
		  $data = file($this->messageDir.DIRECTORY_SEPARATOR.$value);
		  $name  = trim($data[0]);
		  $email = trim($data[1]);
		 $submitDate = trim($data[2]);
		 $ip = trim($data[3]);
		 unset ($data['0']);
		 unset ($data['1']);
		 unset ($data['2']);
		 unset ($data['3']);
		  
		 $content = "";
		 foreach ($data as $value) {
			   $content .= $value;
		 }
		  
		  echo "<tr><th align='left'><a href=\"mailto:$email\">$name</a></th>
					<th class='right'>$submitDate</th></tr>";
		  echo "<tr><td colspan='2'>".nl2br(htmlspecialchars($content))."<br/></td></tr>";
		echo "<tr><td colspan='2'>$ip<br/></td></tr>";
	  }
	  echo "</table>";
	  if (sizeof($list) == 0){
		 echo "<center><p>No messages at the moment!</p><p>&nbsp;</p></center>";
	  }
	  // Create pagination
	  if (sizeof($list) > $this->itemsPerPage){
		 echo "<div id=\"navigation\">";
		 if ($startItem == 0) {
			if ($endItem < sizeof($list)){
			   echo "<div id=\"nright\">
<a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>";
			} else {
			   // Nothing to display
			}
		 } else {
			if ($endItem < sizeof($list)){
			   echo "<div id=\"nleft\">
<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>";
			   echo "<div id=\"nright\">
<a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>";
			} else {
			   echo "<div id=\"nleft\">
<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>";
			}
		 }
		 
		 echo "<br/></div><br/>";
	  }
	  echo "<hr />";
	  $this->displayAddForm();
}

function displayAddForm(){
?>  
  <form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	Name:<br/>
	<input type="text" name="name" size="30"/><br/><br/>
	Email:<br/>
	<input type="text" name="email" size="30"/><br/><br/>
	Your message:<br/>
	<textarea name="message" rows="7" cols="49"></textarea><br/>
	<center><input type="submit" name="submit" value="Save" /></center>
  </form> 
   
<?php   
}

function insertMessage(){
   $name   = isset($_POST['name']) ? $_POST['name'] : 'Anonymous';
   $email  = isset($_POST['email']) ? $_POST['email'] : '';
   $submitDate  = date($this->dateFormat);
   $content = isset($_POST['message']) ? $_POST['message'] : '';
   
   if (trim($name) == '') $name = 'Anonymous';
   if (strlen($content)<5) {
	  exit();
   }
   
   $filename = date('YmdHis');
   if (!file_exists($this->messageDir)){
	  mkdir($this->messageDir);
   }
   $f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");		 
   fwrite($f,$name."\n");
   fwrite($f,$email."\n");
   fwrite($f,$submitDate."\n");
   fwrite($f,"<span style=color:red>IP : ".$_SERVER['REMOTE_ADDR']."</span>\n");
   fwrite($f,$content."\n");
   fclose($f);
   
}
}
?>

Edited by w3room, 09 January 2012 - 16:06.


#10
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
merge :) multumesc mult!

#11
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
pff...mai am o problema...stiu ca sar putea sa stresez dar...:) ce trebuie sa adaug la acest cod ca sa-mi afiseze mesajele lasate in guest book in ordine...adica cel mai recent mesaj lasat sa fie primul, urmat de celelalte in ordinea datei la care au fost lasate...cum este acum codul, mi le afiseaza amestecat... Mulltumesc.

#12
w3room

w3room

    Senior Member

  • Grup: Senior Members
  • Posts: 2,085
  • Înscris: 22.09.2010

View Postyo_suporter, on 9th January 2012, 22:04, said:

cum este acum codul, mi le afiseaza amestecat...
Cum ți le afișează amestecat ? Nu sunt afișate în funcție de oră ? Fă un print.

#13
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
nu le afiseaza cum ar fi normal in functie de data si ora.. :( uite un print... cum e acum mi le afiseaza in functie de zi cred...de la ziua cea mai mare...29 adica, la ziua cea mai mica...02 adica..

Attached Files


Edited by yo_suporter, 09 January 2012 - 23:34.


#14
w3room

w3room

    Senior Member

  • Grup: Senior Members
  • Posts: 2,085
  • Înscris: 22.09.2010
Mie mi se pare foarte normal cum ți le afișează. E ca la facebook comment. :scratchchin:

#15
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
pai in loc penultimu mesaj din print sa fie afisat primul...ca e lasat pe 09.01.2012....primul mesaj in print este unul lasat pe 29.12.2011...urmat de unul din 27.11.2011, si iar de unul din 24.12.2011...

Edited by yo_suporter, 09 January 2012 - 23:54.


#16
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
uite am mai atasat un print in care am marcat pe el ordinea in care ar fi trebuit sa apara...

Attached Files



#17
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
gata. am rezolvat problema :) ms pentru ajutorul dat pana acum.

Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate