Stránka: 1 z 1
| [ Príspevkov: 20 ] | |
Autor | Správa |
---|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Ahojte mam spravene 2 subory ... index.php a message.php ... ide o jednoduchy chat ... on sice funguje dobre spravy zapisuje do suboru msg.html ... ale chcel by som aby sprava ktora sa ulozi resp. zobrazi potom na nejakej stranke ... myslim nova bola vzdy prva. teraz to mam spravene tak ze nova je furt dole ... poradi mi niekto ??? PS: subor msg.html nejdem pisat sluzi len ako zapisovaci a spolu s index.php je v root ... subor message.php je v zlozke ./chat/ ... dakujem vopred za dobreho radcu.
takze index.php
Kód: <?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Jozef chat</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> var httpObject = null; var link = ""; var timerID = 0; var nickName = "<?php echo $nickname; ?>";
function getHTTPObject(){ if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Váš prehliadač nepodporuje AJAX."); return null; } }
function setOutput(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML += response; objDiv.scrollTop = objDiv.scrollHeight; var inpObj = document.getElementById("msg"); inpObj.value = ""; inpObj.focus(); } }
function setAll(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML = response; objDiv.scrollTop = objDiv.scrollHeight; } }
function doWork(){ httpObject = getHTTPObject(); if (httpObject != null) { link = "chat/message.php?nick="+nickName+"&msg="+document.getElementById('msg').value; httpObject.open("GET", link , true); httpObject.onreadystatechange = setOutput; httpObject.send(null); } }
function doReload(){ httpObject = getHTTPObject(); var randomnumber=Math.floor(Math.random()*10000); if (httpObject != null) { link = "chat/message.php?all=1&rnd="+randomnumber; httpObject.open("GET", link , true); httpObject.onreadystatechange = setAll; httpObject.send(null); } }
function UpdateTimer() { doReload(); timerID = setTimeout("UpdateTimer()", 5000); } function keypressed(e){ if(e.keyCode=='13'){ doWork(); } } </script> </head> <body onload="UpdateTimer();"> <div id="sender" onkeyup="keypressed(event);"> Správa: <input type="text" name="msg" size="30" id="msg" /> <button onclick="doWork();">Go</button> </div> <?php
if (!isset($_SESSION['nickname']) ){ createForm(); } else { $name = isset($_POST['name']) ? $_POST['name'] : "Unnamed"; $_SESSION['nickname'] = $name; ?> <div id="result"> <?php $data = file("chat/msg.html"); foreach ($data as $line) { echo $line; } ?> </div> <?php }
?> </div> </body> A teda message.php Kód: <?php if (isset($_GET['msg'])){ if (file_exists('msg.html')) { $f = fopen('msg.html',"a+"); } else { $f = fopen('msg.html',"w+"); } $nick = isset($_GET['nick']) ? $_GET['nick'] : "Hidden"; $msg = isset($_GET['msg']) ? htmlspecialchars($_GET['msg']) : "."; $line = "<p><span class=\"name\">$nick: </span><span class=\"txt\">$msg</span></p>"; fwrite($f,$line."\r\n"); fclose($f); echo $line; } else if (isset($_GET['all'])) { $flag = file('msg.html'); $content = ""; foreach ($flag as $value) { $content .= $value; } echo $content;
} ?>
|
|
Registrovaný: 04.04.07 Prihlásený: 17.07.24 Príspevky: 532 Témy: 35 | 35 Bydlisko: Bratislava |
skus tam doplnit:
Kód: <div id="result"> <?php $array = ''; $data = file("chat/msg.html"); foreach ($data as $line) { $array[] = $line; } for ($row=count($array)-1;$row>-1;$row--) { echo $array[$row] . '<br>'; } ?> </div>
Neskusal som, ale malo by to ist...
_________________ CPU: AMD Phenom II 940 QUAD X4 BE AM2+, chladic: Arctic Cooling Freezer 64 Pro, RAM: 4GB DDR2 800MHz PC6400, MB: M2N-E SLI, VGA: RX 4870 GAINWARD HD4870 1GB, HDD: WD 1TB, Zdroj: CORSAIR 750W TX |
|
Registrovaný: 27.07.07 Príspevky: 3948 Témy: 51 | 51 Bydlisko: Bratislava |
spravy ukladas do pola, cize ti staci namiesto foreach pouzit iny cyklus, pomocou ktoreho budes vypisovat (ukladat do $content) spravy od konca pola az po zaciatok...
_________________ NTB: Acer Aspire 4820TG 14" | CPU: Intel Core i5 2,53 GHz | VGA: ATI Mobility Radeon HD5650 1GB | RAM: 8GB DDR3 1066 MHz | HDD: 1TB SSD WD BLUE |
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Vyborny napad !!! Tiez som uvazoval podobnym smerom ale ani toto nefunguje ':cry:'
djsulo píše: skus tam doplnit: Kód: <div id="result"> <?php $array = ''; $data = file("chat/msg.html"); foreach ($data as $line) { $array[] = $line; } for ($row=count($array)-1;$row>-1;$row--) { echo $array[$row] . '<br>'; } ?> </div> Neskusal som, ale malo by to ist...
|
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Az tak daleko zasa niesom keby si mi to nejako nazorne aj ukazal ... dakujeeeem
stenley píše: spravy ukladas do pola, cize ti staci namiesto foreach pouzit iny cyklus, pomocou ktoreho budes vypisovat (ukladat do $content) spravy od konca pola az po zaciatok...
|
|
Registrovaný: 04.04.07 Prihlásený: 17.07.24 Príspevky: 532 Témy: 35 | 35 Bydlisko: Bratislava |
zaujimave, pretoze ja som to teraz skusal a mne to vypisuje odzadu z textoveho suboru...
_________________ CPU: AMD Phenom II 940 QUAD X4 BE AM2+, chladic: Arctic Cooling Freezer 64 Pro, RAM: 4GB DDR2 800MHz PC6400, MB: M2N-E SLI, VGA: RX 4870 GAINWARD HD4870 1GB, HDD: WD 1TB, Zdroj: CORSAIR 750W TX |
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Asi to bude v tom ze som trochu zaostali hodis tie kody sem uz po tvojej uprave ??? bol by si zlaty ...
djsulo píše: zaujimave, pretoze ja som to teraz skusal a mne to vypisuje odzadu z textoveho suboru...
|
|
Registrovaný: 04.04.07 Prihlásený: 17.07.24 Príspevky: 532 Témy: 35 | 35 Bydlisko: Bratislava |
iba celkom dole je zmenene vypisovanie, to je vsetko...
Kód: <?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Jozef chat</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> var httpObject = null; var link = ""; var timerID = 0; var nickName = "<?php echo $nickname; ?>";
function getHTTPObject(){ if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Váš prehliadač nepodporuje AJAX."); return null; } }
function setOutput(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML += response; objDiv.scrollTop = objDiv.scrollHeight; var inpObj = document.getElementById("msg"); inpObj.value = ""; inpObj.focus(); } }
function setAll(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML = response; objDiv.scrollTop = objDiv.scrollHeight; } }
function doWork(){ httpObject = getHTTPObject(); if (httpObject != null) { link = "chat/message.php?nick="+nickName+"&msg="+document.getElementById('msg').value; httpObject.open("GET", link , true); httpObject.onreadystatechange = setOutput; httpObject.send(null); } }
function doReload(){ httpObject = getHTTPObject(); var randomnumber=Math.floor(Math.random()*10000); if (httpObject != null) { link = "chat/message.php?all=1&rnd="+randomnumber; httpObject.open("GET", link , true); httpObject.onreadystatechange = setAll; httpObject.send(null); } }
function UpdateTimer() { doReload(); timerID = setTimeout("UpdateTimer()", 5000); } function keypressed(e){ if(e.keyCode=='13'){ doWork(); } } </script> </head> <body onload="UpdateTimer();"> <div id="sender" onkeyup="keypressed(event);"> Správa: <input type="text" name="msg" size="30" id="msg" /> <button onclick="doWork();">Go</button> </div> <?php
if (!isset($_SESSION['nickname']) ){ createForm(); } else { $name = isset($_POST['name']) ? $_POST['name'] : "Unnamed"; $_SESSION['nickname'] = $name; ?> <div id="result"> <?php $array = ''; $data = file("chat/msg.html"); foreach ($data as $line) { $array[] = $line; } for ($row=count($array)-1;$row>-1;$row--) { echo $array[$row] . '<br>'; } ?> </div> <?php }
?> </div> </body>
_________________ CPU: AMD Phenom II 940 QUAD X4 BE AM2+, chladic: Arctic Cooling Freezer 64 Pro, RAM: 4GB DDR2 800MHz PC6400, MB: M2N-E SLI, VGA: RX 4870 GAINWARD HD4870 1GB, HDD: WD 1TB, Zdroj: CORSAIR 750W TX |
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Odzadu myslis tak ze ked odosles 3 spravy, tak tretia je hned pod formularom pre odosielanie a prva je uplne na spodku ??? Bo mne to nerobi ani po skopirovani tvojho kodu ... ta som asi krivý nejaky
|
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
stale mi pise pod formular prvu ... a ostatne pod v poradi ... :-(
|
|
Registrovaný: 04.04.07 Prihlásený: 17.07.24 Príspevky: 532 Témy: 35 | 35 Bydlisko: Bratislava |
ano myslim to tak. vyskusaj si urobit index.php a hod si do neho ten kratky kod, co som posielal ako prvy. vytvor si ten subor msg.html a vpis do neho postupne do riadkov cisla. a ked to spustis, tak ti ich vypise v opacnom poradi, ako su tam nahadzane.
_________________ CPU: AMD Phenom II 940 QUAD X4 BE AM2+, chladic: Arctic Cooling Freezer 64 Pro, RAM: 4GB DDR2 800MHz PC6400, MB: M2N-E SLI, VGA: RX 4870 GAINWARD HD4870 1GB, HDD: WD 1TB, Zdroj: CORSAIR 750W TX |
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 | |
Registrovaný: 04.04.07 Prihlásený: 17.07.24 Príspevky: 532 Témy: 35 | 35 Bydlisko: Bratislava |
Kód: Fatal error: Call to undefined function: createform() in /9p/wz.cz/j/jtomcik/index.php on line 113
niekde si tusim zabudol zavolat funkciu
_________________ CPU: AMD Phenom II 940 QUAD X4 BE AM2+, chladic: Arctic Cooling Freezer 64 Pro, RAM: 4GB DDR2 800MHz PC6400, MB: M2N-E SLI, VGA: RX 4870 GAINWARD HD4870 1GB, HDD: WD 1TB, Zdroj: CORSAIR 750W TX |
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
hmmm ? Ale mne to funguje ... ved si videl na jtomcik.wz.cz ... nechapem tomu fakt ... a pritom je to isto taka sprostost ze koniec ... a neviem na to prist.
|
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
jaaaaaaj hej mmt ...to chce este aj login
|
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Toto je ono uz by to nemalo robit ...
Kód: <?php session_start();
function createForm(){ ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table align="center"> <tr><td colspan="2">Prosím vložte svoj login!</td></tr> <tr><td>Vaše meno: </td> <td><input class="text" type="text" name="name" /></td></tr> <tr><td colspan="2" align="center"> <input class="text" type="submit" name="submitBtn" value="Odoslať" /> </td></tr> </table> </form> <?php }
if (isset($_GET['u'])){ unset($_SESSION['nickname']); }
// Process login info if (isset($_POST['submitBtn'])){ $name = isset($_POST['name']) ? $_POST['name'] : "Unnamed"; $_SESSION['nickname'] = $name; }
$nickname = isset($_SESSION['nickname']) ? $_SESSION['nickname'] : "Hidden"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Jozef chat</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> var httpObject = null; var link = ""; var timerID = 0; var nickName = "<?php echo $nickname; ?>";
function getHTTPObject(){ if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Váš prehliadač nepodporuje AJAX."); return null; } }
function setOutput(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML += response; objDiv.scrollTop = objDiv.scrollHeight; var inpObj = document.getElementById("msg"); inpObj.value = ""; inpObj.focus(); } }
function setAll(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML = response; objDiv.scrollTop = objDiv.scrollHeight; } }
function doWork(){ httpObject = getHTTPObject(); if (httpObject != null) { link = "chat/message.php?nick="+nickName+"&msg="+document.getElementById('msg').value; httpObject.open("GET", link , true); httpObject.onreadystatechange = setOutput; httpObject.send(null); } }
function doReload(){ httpObject = getHTTPObject(); var randomnumber=Math.floor(Math.random()*10000); if (httpObject != null) { link = "chat/message.php?all=1&rnd="+randomnumber; httpObject.open("GET", link , true); httpObject.onreadystatechange = setAll; httpObject.send(null); } }
function UpdateTimer() { doReload(); timerID = setTimeout("UpdateTimer()", 5000); } function keypressed(e){ if(e.keyCode=='13'){ doWork(); } } </script> </head> <body onload="UpdateTimer();"> <div id="sender" onkeyup="keypressed(event);"> Správa: <input type="text" name="msg" size="30" id="msg" /> <button onclick="doWork();">Go</button> </div> <?php
if (!isset($_SESSION['nickname']) ){ createForm(); } else { $name = isset($_POST['name']) ? $_POST['name'] : "Unnamed"; $_SESSION['nickname'] = $name; ?> <div id="result"> <?php $array = ''; $data = file("chat/msg.html"); foreach ($data as $line) { $array[] = $line; } for ($row=count($array)-1;$row>-1;$row--) { echo $array[$row] . '<br>'; } ?> </div> <?php }
?> </body> djsulo píše: Kód: Fatal error: Call to undefined function: createform() in /9p/wz.cz/j/jtomcik/index.php on line 113 niekde si tusim zabudol zavolat funkciu
|
|
Registrovaný: 20.07.08 Príspevky: 474 Témy: 1 | 1 Bydlisko: Kosice |
tak som si pozrel tu stranku, problem je asi v tomto
Kód: <?php $array = ''; $data = file("chat/msg.html"); foreach ($data as $line) { $array[] = $line; } for ($row=count($array)-1;$row>-1;$row--) { echo $array[$row] . '<br>'; } ?>
toto by malo by ten nacitany text rozdelit na riadky a potom vypisovat riadky od zadu, ale ked sa pozries na uz vygenerovany HTML kod v tom chate, tak zistis ze <BR> je tam iba raz to znamena ze tento PHP kod ti nerozdeli riadky => vsetko je iba jeden riadok => stale sa vypisuje rovnako v PHP sa nevyznam, ale co ma byt toto? Kód: foreach ($data as $line) { $array[] = $line; }
ked dobre viem $data je uz pole riadkov, nie? neda sa pouzit toto pole na vypisovanie v tom for cykle?
|
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 |
Ked sa to pusti bey toho <br> tak sa na seba len riadkz viac natestaju ... ale mne ide o to abz poslednz bol prvy ;...
|
|
Registrovaný: 27.07.07 Príspevky: 3948 Témy: 51 | 51 Bydlisko: Bratislava |
samozrejme, ze sa to da pouzit
toto by ti uz malo fungovat, aj ked by som to este trosku upravil, lebo teraz je to pomalsie:
Kód: <?php session_start();
function createForm(){ ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table align="center"> <tr><td colspan="2">Prosím vložte svoj login!</td></tr> <tr><td>Vaše meno: </td> <td><input class="text" type="text" name="name" /></td></tr> <tr><td colspan="2" align="center"> <input class="text" type="submit" name="submitBtn" value="Odoslať" /> </td></tr> </table> </form> <?php }
if (isset($_GET['u'])){ unset($_SESSION['nickname']); }
// Process login info if (isset($_POST['submitBtn'])){ $name = isset($_POST['name']) ? $_POST['name'] : "Unnamed"; $_SESSION['nickname'] = $name; }
$nickname = isset($_SESSION['nickname']) ? $_SESSION['nickname'] : "Hidden"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Jozef chat</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript">
var httpObject = null; var link = ""; var timerID = 0; var nickName = "<?php echo $nickname; ?>";
function getHTTPObject(){ if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Váš prehliadač nepodporuje AJAX."); return null; } }
function setOutput(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); //objDiv.innerHTML += response; objDiv.scrollTop = objDiv.scrollHeight; var inpObj = document.getElementById("msg"); inpObj.value = ""; inpObj.focus(); } }
function setAll(){ if(httpObject.readyState == 4){ var response = httpObject.responseText; var objDiv = document.getElementById("result"); objDiv.innerHTML = response; objDiv.scrollTop = objDiv.scrollHeight; } }
function doWork(){ httpObject = getHTTPObject(); if (httpObject != null) { link = "chat/message.php?nick="+nickName+"&msg="+document.getElementById('msg').value; httpObject.open("GET", link , true); httpObject.onreadystatechange = setOutput; httpObject.send(null); } }
function doReload(){ httpObject = getHTTPObject(); var randomnumber=Math.floor(Math.random()*10000); if (httpObject != null) { link = "chat/message.php?all=1&rnd="+randomnumber; httpObject.open("GET", link , true); httpObject.onreadystatechange = setAll; httpObject.send(null); } }
function UpdateTimer() { doReload(); timerID = setTimeout("UpdateTimer()", 5000); }
function keypressed(e){ if(e.keyCode=='13'){ doWork(); } }
</script> </head> <body onload="UpdateTimer();"> <div id="sender" onkeyup="keypressed(event);"> Správa: <input type="text" name="msg" size="30" id="msg" /> <button onclick="doWork();">Go</button> </div> <?php
if (!isset($_SESSION['nickname']) ){ createForm(); } else { $name = isset($_POST['name']) ? $_POST['name'] : "Unnamed"; $_SESSION['nickname'] = $name; ?>
<div id="result"> <?php $data = file("chat/msg.html"); for($i=count($data)-1; $i>=0; $i--) { echo $data[$i]; } /*foreach ($data as $line) { echo $line; }*/ ?> </div> <?php }
?> </div> </body> message.php Kód: <?php if (isset($_GET['msg'])){ if (file_exists('msg.html')) { $f = fopen('msg.html',"a+"); } else { $f = fopen('msg.html',"w+"); } $nick = isset($_GET['nick']) ? $_GET['nick'] : "Hidden"; $msg = isset($_GET['msg']) ? htmlspecialchars($_GET['msg']) : "."; $line = "<p><span class=\"name\">$nick: </span><span class=\"txt\">$msg</span></p>"; fwrite($f,$line."\r\n"); fclose($f);
//echo $line;
} //if (isset($_GET['all'])) { $flag = file('msg.html'); $content = ""; for($i=count($flag)-1; $i>=0; $i--) { $content .= $flag[$i]; } /*foreach ($flag as $value) { $content .= $value; }*/ echo $content;
//} ?>
_________________ NTB: Acer Aspire 4820TG 14" | CPU: Intel Core i5 2,53 GHz | VGA: ATI Mobility Radeon HD5650 1GB | RAM: 8GB DDR3 1066 MHz | HDD: 1TB SSD WD BLUE |
|
Registrovaný: 06.09.07 Prihlásený: 21.03.24 Príspevky: 263 Témy: 62 | 62 | |
Stránka: 1 z 1
| [ Príspevkov: 20 ] | |
|