variabila IP
Last Updated: Jan 10 2012 19:54, Started by
yo_suporter
, Jan 07 2012 19:38
·
0
#1
Posted 07 January 2012 - 19:37
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> </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 »</a></div>"; } else { // Nothing to display } } else { if ($endItem < sizeof($list)){ echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >« Pagina anterioara</a></div>"; echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Pagina urmatoare »</a></div>"; } else { echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >« 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
Posted 07 January 2012 - 20:44
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
Posted 07 January 2012 - 21:14
merge...multumesc mult!
Edited by yo_suporter, 07 January 2012 - 21:20. |
#4
Posted 07 January 2012 - 21:19
yo_suporter, on 7th January 2012, 21:14, said: daca fac modificarea asta...nu imi mai apare nimic...adica nu mi se mai deschide guestbookul... 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
Posted 07 January 2012 - 21:35
gata...merge. multumesc mult!
Edited by yo_suporter, 07 January 2012 - 21:35. |
#6
Posted 09 January 2012 - 04:04
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
Posted 09 January 2012 - 11:28
fwrite($f,"<span style=color:red>IP : ".$_SERVER['REMOTE_ADDR']."</span>"); Edited by w3room, 09 January 2012 - 11:28. |
#8
Posted 09 January 2012 - 13:12
nu se schimba culoarea...imi da eroare...imi apare asa: <span=color:red>IP : xxxxxxxx</span>
|
#9
Posted 09 January 2012 - 16:04
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> </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 »</a></div>"; } else { // Nothing to display } } else { if ($endItem < sizeof($list)){ echo "<div id=\"nleft\"> <a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >« Prev</a></div>"; echo "<div id=\"nright\"> <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next »</a></div>"; } else { echo "<div id=\"nleft\"> <a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >« 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. |
#11
Posted 09 January 2012 - 22:04
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
Posted 09 January 2012 - 22:54
#13
Posted 09 January 2012 - 23:28
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 FilesEdited by yo_suporter, 09 January 2012 - 23:34. |
#14
Posted 09 January 2012 - 23:39
Mie mi se pare foarte normal cum ți le afișează. E ca la facebook comment.
|
#15
Posted 09 January 2012 - 23:50
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
Posted 10 January 2012 - 01:03
uite am mai atasat un print in care am marcat pe el ordinea in care ar fi trebuit sa apara...
Attached Files |
#17
Posted 10 January 2012 - 19:54
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