Jump to content

php_joe

Members
  • Posts

    175
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://darkswords.joescuriosityshoppe.com

Profile Information

  • Gender
    Not Telling

php_joe's Achievements

Member

Member (2/5)

0

Reputation

  1. Oh, sorry dzelenika, I didn't see your suggestion before. Your modification fixed the error, thanks!
  2. Thank you , However, that code returns the same value as the one I wrote. I guess the problem is with my spreadsheet's STDEV function. Joe
  3. Hello, I am trying to write a function that will calculate the standard deviation of values in an array. I did search past topics and used them to come up with this script: function standard_deviation($sample){ if(is_array($sample)){ $mean = array_sum($sample) / count($sample); foreach($sample as $key => $num) $devs[$key] = pow($num - $mean, 2); return sqrt(array_sum($devs) / count($devs)); } } It seems to work, but I get different values when I've checked it by using STDEV in OpenOffice, so I think I've made an error somewhere.
  4. Hi, Is there any way to edit the last modified date of the files on my web server? Thanks, Joe
  5. <?php // // This sample shows how to fill in and submit data to a form that looks like: // // <form enctype="multipart/form-data" // action="somewhere.cgi" method="post"> // <input type="file" name="sampfile"> // <input type="text" name="filename"> // <input type="text" name="shoesize"> // <input type="submit" value="upload"> // </form> // // Pay attention to: // #1 - the input field names (name=) // #2 - the input field type so that you pass the upload file to the right // name // #3 - what URL to send the POST to. The action= attribute sets it. // // Author: Daniel Stenberg $uploadfile="/tmp/mydog.jpg"; $ch = curl_init("http://formsite.com/somewhere.cgi"); curl_setopt($ch, CURLOPT_POSTFIELDS, array('sampfile'=>"@$uploadfile", 'shoesize'=>'9', 'filename'=>"fake name for file")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $postResult = curl_exec($ch); curl_close($ch); print "$postResult"; } ?>
  6. Change $i to $i0 and then use this code before the <select> tag: <? if($monkskin) $i$monkskin = "selected": ?>
  7. You're more likely to get a response if you include a specific example of the code you're having problems with.
  8. I was trying CURL originally, because I wanted to log in and submit an action. It timed out, so I tried file_get_contents() as a test, and it timed out too. file_get_contents() works fine for every other site that I've tried it on. The error code I'm getting says this: Warning: file_get_contents(http://shop.darkswords.ru) [function.file-get-contents]: failed to open stream: Connection timed out in /hsphere/local/home/mysite.com/testfile.php on line 2 I'm wondering if it has something to do with the encoding. The site was written and hosted in Russia, and the comments are in Russian. Could there be some kind of (human) language-based incompatibility? Joe
  9. Hi, I'm having problems getting information from a website. Whatever I do times out. Even a simple code like this: <?php echo file_get_contents("http://shop.darkswords.ru"); ?> Here is the address: http://shop.darkswords.ru I can't figure out what's wrong. Thanks! Joe
  10. I know how to set a cookie using setcookie(), but can a website set cookies with another website's name on them? For example, if I have a website, http://www.mysite.com, could I set a cookie for http://www.someothersite.com? There is a website that I send referrals to, but they're mad at me. They claim that I'm setting referral cookies on my site.
  11. Ok, I can't figure out what I'm doing wrong. I got this simple chat script that uses mySQL and I've been trying to modify it so it's flat-file, but I just can't get it to work. The script uses 3 pages. The first is the chat window, the second is a php file that stores the recent posts, and the third writes new posts to the second file and then displays any posts that havn't been read by the viewer yet. This is the chat file: <html> <head> <title>AJAX Driven Web Chat</title> <style type="text/css" media="screen"> .chat_time { font-style: italic; font-size: 9px; } </style> <script language="JavaScript" type="text/javascript"> var sendReq = getXmlHttpRequestObject(); var receiveReq = getXmlHttpRequestObject(); var lastMessage = 0; var mTimer; //Function for initializating the page. function startChat() { //Set the focus to the Message Box. document.getElementById('txt_message').focus(); //Start Recieving Messages. getChatText(); } //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.'; } } //Gets the current messages from the server function getChatText() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { //if(typeof lastMessage=="undefined") alert("undefined"); //else alert(lastMessage); receiveReq.open("GET", 'getChat.php?chat=1&last=' + lastMessage, true); alert('getChat.php?chat=1&last=' + lastMessage); receiveReq.onreadystatechange = handleReceiveChat; receiveReq.send(null); } } //Add a message to the chat server. function sendChatText() { if(document.getElementById('txt_message').value == '') { alert("You have not entered a message"); return; } if (sendReq.readyState == 4 || sendReq.readyState == 0) { sendReq.open("POST", 'getChat.php?chat=1&last=' + lastMessage, true); sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); sendReq.onreadystatechange = handleSendChat; var param = 'message=' + document.getElementById('txt_message').value; param += '&name=Ryan Smith'; param += '&chat=1'; sendReq.send(param); document.getElementById('txt_message').value = ''; } } //When our message has been sent, update our page. function handleSendChat() { //Clear out the existing timer so we don't have //multiple timer instances running. clearInterval(mTimer); getChatText(); } //Function for handling the return of chat text function handleReceiveChat() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); var n_messages = message_nodes.length for (i = 0; i < n_messages; i++) { var user_node = message_nodes[i].getElementsByTagName("user"); var text_node = message_nodes[i].getElementsByTagName("text"); var time_node = message_nodes[i].getElementsByTagName("time"); lastMessage = (message_nodes[i].getAttribute('id')); chat_div.innerHTML += '<span class="chat_time">'; chat_div.innerHTML += time_node[0].firstChild.nodeValue; chat_div.innerHTML += "</span> [<span class='user'>"; chat_div.innerHTML += user_node[0].firstChild.nodeValue; chat_div.innerHTML += '</span>]: '; chat_div.innerHTML += last[0].firstChild.nodeValue + ' - '; chat_div.innerHTML += text_node[0].firstChild.nodeValue + '<br />'; chat_div.scrollTop = chat_div.scrollHeight; } mTimer = setTimeout('getChatText();',2000); //Refresh our chat in 2 seconds } } //This functions handles when the user presses enter. Instead of submitting the form, we //send a new message to the server and return false. function blockSubmit() { sendChatText(); return false; } //This cleans out the database so we can start a new chat session. function resetChat() { if (sendReq.readyState == 4 || sendReq.readyState == 0) { sendReq.open("POST", 'getChat.php?chat=1&last=' + lastMessage, true); sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); sendReq.onreadystatechange = handleResetChat; var param = 'action=reset'; sendReq.send(param); document.getElementById('txt_message').value = ''; } } //This function handles the response after the page has been refreshed. function handleResetChat() { document.getElementById('div_chat').innerHTML = ''; getChatText(); } </script> </head> <body onload="javascript:startChat();"> <h2><a href="http://www.dynamicAJAX.com" style="color: #000000; text-decoration: none;">AJAX Driven Web Chat</a></h2> <p id="p_status">Status: Normal</p> Current Chitter-Chatter: <div id="div_chat" style="height: 300px; width: 500px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"> </div> <form id="frmmain" name="frmmain" onsubmit="return blockSubmit();"> <input type="button" name="btn_get_chat" id="btn_get_chat" value="Refresh Chat" onclick="javascript:getChatText();" /> <input type="button" name="btn_reset_chat" id="btn_reset_chat" value="Reset Chat" onclick="javascript:resetChat();" /><br /> <input type="text" id="txt_message" name="txt_message" style="width: 447px;" /> <input type="button" name="btn_send_chat" id="btn_send_chat" value="Send" onclick="javascript:sendChatText();" /> </form> </body> </html> And here is the getchat file: <?php function displayheaders(){ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header("Cache-Control: no-cache, must-revalidate" ); header("Pragma: no-cache" ); header("Content-Type: text/xml; charset=utf-8"); } $time = explode('|', gmdate("Y|z|H|i|s")); $micro = number_format(microtime(), 3); $seconds = $time[3] . $time[4]; $messageday = $time[0] . $time[1] . $time[2]; $messagetime = (($seconds+$micro)*1000); if(!$last) $last = '000000000.0000000'; $last = explode('.', $last); displayheaders(); //Send headers to prevent caching. $database = "./db.php"; if(file_exists($database)) require $database; else die('Error: database missing.'); if(isset($_POST['message']) && $message != '') { //Check to see if a message was sent. $msg[$messageday][$messagetime] = array("$time[2]:$time[3]:$time[4]", 'Admin', 'public', $message); if($msg) foreach($msg as $key1 => $value) { if($key1 >= $messageday) foreach($msg[$key1] as $key2 => $value) { if($key2 > ($messagetime - 10)) { $newline[$key2] = '$msg[' . $key1 . '][' . $key2 . '] = array("' . "$time[2]:$time[3]:$time[4]\", 'Admin', 'public', $value" . ');'; } } } if($newline) $info = "<?php\n" . implode("\n", $newline) . "\n?>"; $handle = fopen("./db.php", 'w'); fwrite($handle, $info); fclose($handle); } $xml = '<?xml version="1.0" ?><root>'; if($msg) foreach($msg as $key1 => $value) { if($key1 >= $last[0]) foreach($msg[$key1] as $key2 => $value) { if($key2 > $last[1]) { $xml .= "<message id='" . $key1 . '.' . $key2 . "'>"; $xml .= "<time>". $msg[$key1][$key2][0] . "</time>"; $xml .= "<user>". $msg[$key1][$key2][1] . "</user>"; $xml .= "<type>". $msg[$key1][$key2][2] . "</type>"; $xml .= "<text>". $msg[$key1][$key2][3] . "</text>"; $xml .= "</message>"; } } }else{ $xml .= "<message id='" . $messageday . '.' . $messagetime . "'>"; $xml .= "<time></time>"; $xml .= "<user></user>"; $xml .= "<type></type>"; $xml .= "<text></text>"; $xml .= "</message>"; } $xml .= '</root>'; echo $xml; ?> The messages are stored on db.php like this: <?php $msg[200812107][4525944] = array('07:45:25', 'Admin', 'public', 'Hello'); $msg[200812107][4526944] = array('07:45:26', 'Admin', 'public', 'This is a test'); $msg[200812107][4527944] = array('07:45:27', 'Admin', 'public', 'This is a line'); $msg[200812107][4528944] = array('07:45:28', 'Admin', 'public', 'Goodbye'); ?> Now, the AJAX on the main page should call something like getchat.php?last=20080429.8765476 getchat.php should then display any messages with keys higher than $last. When I change the AJAX to display the "last" variable it shows up correctly, and when I open getchat.php and $_GET $last then the xml displays correctly, but the messages don't show up in the chat window... :'(
  12. I thought that keys couldn't be longer than 10 digits. I seem to remember trying a single key at first, but getting errors.
  13. I have a list of arrays like this: <? $msg[2008][105][7][45][18][0] = array("7:45:18", "Admin", "public", "Hello."); $msg[2008][105][7][45][19][0] = array("7:45:19", "Admin", "public", "This is a test."); $msg[2008][105][7][45][20][0] = array("7:45:20", "Admin", "public", "This is only a test."); $msg[2008][105][7][45][21][0] = array("7:45:21", "Admin", "public", "If this were a real chat."); $msg[2008][105][7][45][22][0] = array("7:45:22", "Admin", "public", "I wouldn't be talking to myself."); ?> I want to process only the arrays that follow a specified key, such as $msg[2008][105][7][45][20][0]. I wrote this code, but it processes every array, not just the ones following $msg[2008][105][7][45][20][0]. <? $last = "2008.105.7.45.20.0"; // <== the keys are year, day, hour, minute, second, and microsecond $last2 = explode('.', $last); if($msg){ if($msg) foreach($msg as $key_year => $value1){ if($key_year >= $last2[0]) foreach($msg[$key_year] as $key_day => $value2){ if($key_day >= $last2[1]) foreach($msg[$key_year][$key_day] as $key_hour => $value3){ if($key_hour >= $last2[2]) foreach($msg[$key_year][$key_day][$key_hour] as $key_min => $value4){ if($key_min >= $last2[3]) foreach($msg[$key_year][$key_day][$key_hour][$key_min] as $key_sec => $value5){ foreach($msg[$key_year][$key_day][$key_hour][$key_min][$key_sec] as $key_micro => $piece){ if($key_sec > $last2[4]) $text .= display_text($piece); if($key_sec = $last2[4] && $key_micro >= $last2[5]) $text .= display_text($piece); } } } } } } } ?> What have I done wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.