Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Converting 12 Hours Format to 24 Hrs Format
Psycho replied to suresh64633's topic in Javascript Help
Improved the function. - 00:00 should be used instead of 24:00 - added functionality to ensure hours is always two digits. function convert12to24(timeStr) { var meridian = timeStr.substr(timeStr.length-2).toLowerCase(); var hours = timeStr.substring(0, timeStr.indexOf(':')); var minutes = timeStr.substring(timeStr.indexOf(':')+1, timeStr.indexOf(' ')); if (meridian=='pm') { hours = (hours=='12') ? '00' : parseInt(hours)+12 ; } else if(hours.length<2) { hours = '0' + hours; } return hours+':'+minutes; } -
with an eval in there it definitely doesn't do anything good. It looks like it is running the function against all the values in $_SERVER. I doubt it was put there by someone with your FTP account info. I would guess there is a security hole in your verions of wordpress which someone has exploited. You should update to the current version and/or check forums about any security holes and ways to patch. By the way the code can be put into [ p h p ] tags just fine on here. it's just that there are so many leading spaces that the code is way out to the right. You would have to scroll to the right to see it.
-
Converting 12 Hours Format to 24 Hrs Format
Psycho replied to suresh64633's topic in Javascript Help
<html> <head> <script type="text/javascript"> function convert12to24(timeStr) { var meridian = timeStr.substr(timeStr.length-2).toLowerCase();; var hours = timeStr.substr(0, timeStr.indexOf(':')); var minutes = timeStr.substring(timeStr.indexOf(':')+1, timeStr.indexOf(' ')); if (meridian=='pm') { if (hours!=12) { hours=hours*1+12; } else { hours = (minutes!='00') ? '0' : '24' ; } } return hours+':'+minutes; } //This function only for testing function changeTimeFormat() { var input = document.getElementById('input').value var output = convert12to24(input); document.getElementById('output').value = output; } </script> </head> <body> Input 12 hr format: <input type="text" name="input" value="10:30 PM"><br /> Output 24 hr format: <input type="text" name="output" value="" readonly> <button onclick="changeTimeFormat();">Change</button> </form> </body> </html> -
[SOLVED] PHP Multi-Language code help
Psycho replied to worldcomingtoanend's topic in PHP Coding Help
You apparently have a field called "txtclick" (although you are referencing the field incorrectly - the field name should be in quote marks). And you are assuming the value indicates that the user want's to change their language from the current page. That would work, but I think it would make more sense to pass a value to explicitly set the language. So, on the German pages pass a value of "en" and on the English pages pass a value of "de" (using the standard lanugage abbreviations). I am also assuming that you have parrallel pages for each language as opposed to one page which uses different content based on the language. It would be helpful to know how you named the pages in order to show how you would change the page. But, generally speaking I would put code at the top of the page to do the following 1. Check if the "change Language" option was POSTED. 2. If yes, then get the current URL 3. Modify the current URL to the other language equivalent 4. Do a header redirect to the new URL -
The logic of what you are asking is fairly simple, but as AlexWD has pointed out it would just be a theoretical exercise as you would need the computing power of a million deep blue's or maybe several million cuda enabled GPUs in order to accomplish this before the sun exploded. To complete this process in one year's time the computer would have to process roughly 10,790,283,070,806,014,188,970,529,154,990 records per second! Assuming, your system could process 1 million records a second (which I doubt it can) it would take 10,790,283,070,806,014,188,970,529 years to process all the combinations. To put that into perspective, the earth is believed to be only 4,500,000,000 years old.
-
To your first question, I would state that is the "preferred" method (but, that is debatable). As for the second question the answer is yes as well. Just about any PHP programme worth his salt is going to tell you that you should separate the logic (PHP) and the presentation (HTM/CSS) of your pages. It makes things MUCH easier to debug and to make changes later. It also makes development much easier as you don't have to mentally interpret the PHP code and the HTML together. For instance, taking the example Bricktop posted, let's say the URL of the hyperlink can be dynamic based upon time of day. Some people might write it like this <div class="someclass"> <?php $hour = date('G'); if($hour<6) { echo "<a href="night.php">Hello World!</a>"; } elseif ($hour<12) { echo "<a href="morning.php">Hello World!</a>"; } elseif ($hour<18) { echo "<a href="afternoon.php">Hello World!</a>"; } elseif ($hour<24) { echo "<a href="evening.php">Hello World!</a>"; } ?> </div> However, I believe that this would be a better approach: At top of page or in separate file <?php $hour = date('G'); if($hour<6) { $helloWorldURL = 'night.php'; } elseif ($hour<12) { $helloWorldURL = 'morning.php'; } elseif ($hour<18) { $helloWorldURL = 'afternoon.php'; } elseif ($hour<24) { $helloWorldURL = 'evening.php'; } ?> At bottom of page where HTML is declared or in included file <div class="someclass"> <a href="<?php echo $helloWorldURL; ?>">Hello World!</a> </div> A quick look at the presentation (HTML) shows exactly what the page should look like. If there is a problem with the URL you know where to look. And, if needed you can quickly debug the script to determine if you have an HTML or PHP problem. By combining the HTML and PHP it can sometimes be difficult to determine where the problem really is. Plus, you have the flexibility of changing your design very easily without risking regression in your logic.
-
No, they are not. There are several missing brackets in the first function. In any even't I see a lot of problems with the code. For example in the first function: for (var i = 0, j = 0; i < els.length; i++) { if (pattern.test(els[i].className)) { classElements[j] = els[i]; // retrieve all elements of a given class } } The will keep settin classElements[0] equal to each value in els, so when the loop ends it only has the last value saved. There are also two functions titled getElementsByClass(). I think you just copied and pasted part of the first function by mistake Not tested - just fixed what I thought were mistakes // retrieve all elements of a given class function getElementsByClass(search) { var classElements = new Array(); var els = document.getElementsByTagName('*'); var pattern = new RegExp('(^|\\s)' + search + '(\\s|$)'); for (var i = 0, j = 0; i < els.length; i++) { if (pattern.test(els[i].className)) { classElements[j] = els[i]; } } } // remove the highlighting on mouseout function unhighlightTableRow(e) { e.style.backgroundColor = ''; } // register event handlers and set initial view window.onload = function() { window.directory = '/'; // current directory viewed window.filename = ''; // currently selected file // event handlers document.getElementById('btn_open').onclick = openSelected; document.getElementById('btn_new_folder').onclick = showNewFolder; document.getElementById('form_new_submit').onclick = doNewFolder; document.getElementById('form_new_reset').onclick = hideForms; document.getElementById('btn_upload').onclick = showUploadFile; document.getElementById('form_upload').target = 'my_iframe'; document.getElementById('form_upload_submit').onclick = doUploadFile; document.getElementById('form_upload_reset').onclick = hideForms; document.getElementById('btn_rename').onclick = showRename; document.getElementById('form_rename_submit').onclick = doRename; document.getElementById('form_rename_reset').onclick = hideForms; document.getElementById('btn_delete').onclick = doDelete; // load the file listing refreshFilesList(); } // retrieve display of files and directories function refreshFilesList() { hideForms(); var url = 'process.php?action=list & dir=' + window.directory + ' & nocache=' + (new Date()).getTime(); window.httpObj = createXMLHTTPObject(); window.httpObj.open('GET', url , true); window.httpObj.onreadystatechange = function() { if (window.httpObj.readyState == 4 & window.httpObj.responseText) { // populate the fields document.getElementById('file_datagrid').innerHTML = window.httpObj.responseText; window.filename = ''; // selected file } } window.httpObj.send(null); } // hide all input forms function hideForms() { document.getElementById('form_new').style.display = 'none'; document.getElementById('form_rename').style.display = 'none'; document.getElementById('form_upload').style.display = 'none'; } // alert user the upload failed function uploadFailed() { alert('Failed to upload file.'); hideForms(); } // show form to upload a new file function showUploadFile() { hideForms(); document.getElementById('form_upload').reset(); document.getElementById('form_upload').style.display = ''; } // set form_upload_directory (allow browser to handle form // submission) function doUploadFile() { document.getElementById('form_upload_directory').value = window.directory; } // show form to create new folder function showNewFolder() { hideForms(); document.getElementById('form_new_name').value = ''; document.getElementById('form_new').style.display = ''; } // create a new folder function doNewFolder() { var url = 'process.php?action=new & dir=' + window.directory + ' & name=' + document.getElementById('form_new_name').value + ' & nocache=' + (new Date()).getTime(); window.httpObj = createXMLHTTPObject(); window.httpObj.open('GET', url , true); window.httpObj.onreadystatechange = function() { if (window.httpObj.readyState == 4 & window.httpObj.responseText) { if (window.httpObj.responseText == 'OK') { refreshFilesList(); } else { alert('Unable to create directory.'); } } } window.httpObj.send(null); return false; } // show form to rename a file or directory function showRename() { // don't rename a parent directory or if no file is selected if (window.filename == '..' || window.filename == '') { return; } hideForms(); document.getElementById('form_rename_name').value = window.filename; document.getElementById('form_rename').style.display = ''; } // rename the file or directory function doRename() { var url = 'process.php?action=rename & dir=' + window.directory + ' & oldfile=' + window.filename + ' & newfile=' + document.getElementById('form_rename_name').value + ' & nocache=' + (new Date()).getTime(); window.httpObj = createXMLHTTPObject(); window.httpObj.open('GET', url , true); window.httpObj.onreadystatechange = function() { if (window.httpObj.readyState == 4 & window.httpObj.responseText) { if (window.httpObj.responseText == 'OK') { refreshFilesList(); } else { alert('Unable to rename entry.'); } } } window.httpObj.send(null); return false; } // delete a directory or file function doDelete() { // don't delete a parent directory or if no file is selected if (window.filename == '..' || window.filename == '') { return; } if (!confirm('Are you sure you wish to delete?')) { return; } var url = 'process.php?action=delete & dir=' + window.directory + ' & file=' + window.filename + ' & nocache=' + (new Date()).getTime(); window.httpObj = createXMLHTTPObject(); window.httpObj.open('GET', url , true); window.httpObj.onreadystatechange = function() { if (window.httpObj.readyState == 4 & window.httpObj.responseText) { if (window.httpObj.responseText == 'OK') { refreshFilesList(); } else { alert('Unable to delete entry.'); } } } httpObj.send(null); } // download the selected file or traverse into the selected directory function openSelected() { var url = 'process.php?action=open & dir=' + window.directory + ' & file=' + window.filename + ' & nocache=' + (new Date()).getTime(); window.httpObj = createXMLHTTPObject(); window.httpObj.open('GET', url , true); window.httpObj.onreadystatechange = function() { if (window.httpObj.readyState == 4 & window.httpObj.responseText) { var result = eval('(' + window.httpObj.responseText + ')'); if (result.retType == 'directory') { window.directory = result.directory; refreshFilesList(); } else if (result.retType == 'file') { window.location = 'download.php? & dir=' + window.directory + ' & file=' + window.filename + ' & nocache=' + (new Date()).getTime(); } else { alert('Unknown error.'); } } } window.httpObj.send(null); return false; }
-
[SOLVED] echo "attack".$row['user_name'];
Psycho replied to markvaughn2006's topic in PHP Coding Help
Pointer #1 use CODE tags when posting !!! I'm assuming that each user has an ID (and that the current user's ID is stored in a session variable). You will want to pass the ID of the user to be attacked when the "Attack" is clicked. You can either use a hyperlink where the link has the user to be attacked ID is included or you can use a button with a form (you could use a button with just JavaScript, but that is typically frowned upon). If using a button and a form you can use either GET or POST. Some people do not like using GET because they don't want the user to see the data on the query string. But, using a form with GET allows you to use a form or normal hyperlink or both. So, I will use that for the example. I would also suggest separating your logic from the actual HTML output. Makes things much easier. <?php $query = "SELECT id, user_name FROM users_tbl WHERE location='Ye Olde Tavern'"; $result = mysql_query($query) or die(mysql_error()); $attackList = ''; while ($row = mysql_fetch_array($result)) { $attackList .= "{$row['user_name']}<br />"; $attackList .= "<form action="attack.php" method="GET">"; $attackList .= "<input type="hidden" name="attack_id" value="{$row['id']}">"; $attackList .= "<button type="submit">Attack</button>"; $attackList .= "</form><br /> "; } ?> Rivals:<br /> <?php echo $attackList; ?> NOTE: FORMs have default padding top and bottom which might spread our the names vertically more than you would like. You can "fix" that by including style attributes in your form tags or by using a class or style properties on the page as a whole. -
create automatic href for specified keywors and key phrases
Psycho replied to dflow's topic in PHP Coding Help
preg_replace() See example #2 http://us3.php.net/manual/en/function.preg-replace.php Or maybe, preg_replace_callback http://us3.php.net/manual/en/function.preg-replace-callback.php -
Here's a very rough draft. <?php $eventID = (int) $_GET['eventID']; $query = "SELECT * FROM events WHERE id='{$eventID}'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)==0) { die("No event matches the id '{$eventID}'"); } $event = mysql_fetch_assoc($result); ?> <html> <head> <title>Event Details</title> </head> <body> <h1>Event name: <?php echo $event['name']; ?></h1> <br> Date: <?php echo $event['date']; ?> Time: <?php echo $event['time']; ?> <br> Description: <?php echo $event['description']; ?> </body> </html>
-
Then you will need to learn PHP or some other server-side language. Basically you want to create a page that will get the details of the selected item and output it in a predefined format. You could pass the id of the item on the URL like this: http://mysite.com/getEvent.php?eventID=3 So, when you display the page with all the events listed use the PHP code to create a link for each one with the appropriate ID number. There's more to it than that, of course, but too much to try and explain in a forum post. It's not an exceptionally hard project, though. Start by creating a hard coded page with how the details will be displayed. Then modify the page to get the details from the database and populate the information.
-
Better in what sense? You haven't explained what you are trying to accomplish so there is no way for us to detemin what approach would be better or worse. You might as well say "I came up with the number 529, can anyone come up with a better number?"
-
All I did was find some code with a simple Google search then "improved" it a little. I've updated to maintain the cursor position in FF. I have only done limited testing in IE & FF, but it all appears to work correctly: <html> <head> <style> button { width:30px; } </style> <script type="text/javascript"> function insertAtCursor(fieldID, insertValue) { var fieldObj = document.getElementById(fieldID); if (document.selection) { //IE support fieldObj.focus(); document.selection.createRange().text = insertValue; } else if (fieldObj.selectionStart || fieldObj.selectionStart=='0') { //MOZILLA/NETSCAPE support endPos = fieldObj.selectionStart+1; fieldObj.value = fieldObj.value.substring(0, fieldObj.selectionStart) + insertValue + fieldObj.value.substring(fieldObj.selectionEnd, fieldObj.value.length); fieldObj.selectionStart = endPos fieldObj.selectionEnd = endPos fieldObj.focus(); } else { fieldObj.value += insertValue; } } </script> </head> <body> <button onclick="insertAtCursor('txtarea1', 'à');">à</button> <button onclick="insertAtCursor('txtarea1', 'è');">è</button> <button onclick="insertAtCursor('txtarea1', 'í');">í</button> <button onclick="insertAtCursor('txtarea1', 'ó');">ó</button> <button onclick="insertAtCursor('txtarea1', 'ú');">ú</button> <br /><textarea id="txtarea1" rows="10" cols="40"></textarea> </body> </html>
-
function writeCmd() { // var div = top.buttonFrame.document.getElementById("buttonList"); var htmlText = ''; for(var i=0; i<arrCtr; i++) { htmlText += '<input type="Button" value="' + buttonTXT[i] + '" id="' + buttonIDS[i] + '"'; htmlText += ' name="' + buttonIDS[i] + '" class="submenu_special"'; htmlText += ' onclick="top.contentFrame.document.forms[0].submit()" /><br />'; } top.buttonFrame.document.getElementById('buttonList').innerHTML = htmlText; }
-
No, this is a Javascript problem. The follwoing should help you. One bug I just noticed is that when insterting a character in FF the cursor position is lost after the insertion. I'm too lazy to fix it right now. <html> <head> <style> button { width:30px; } </style> <script type="text/javascript"> function insertAtCursor(fieldID, insertValue) { var fieldObj = document.getElementById(fieldID); if (document.selection) { //IE support fieldObj.focus(); document.selection.createRange().text = insertValue; } else if (fieldObj.selectionStart || fieldObj.selectionStart=='0') { //MOZILLA/NETSCAPE support fieldObj.value = fieldObj.value.substring(0, fieldObj.selectionStart) + insertValue + fieldObj.value.substring(fieldObj.selectionEnd, fieldObj.value.length); } else { fieldObj.value += insertValue; } } </script> </head> <body> <button onclick="insertAtCursor('txtarea1', 'à');">à</button> <button onclick="insertAtCursor('txtarea1', 'è');">è</button> <button onclick="insertAtCursor('txtarea1', 'í');">í</button> <button onclick="insertAtCursor('txtarea1', 'ó');">ó</button> <button onclick="insertAtCursor('txtarea1', 'ú');">ú</button> <br /><textarea id="txtarea1" rows="10" cols="40"></textarea> </body> </html>
-
What is exporting .php file to other types of file extension?
Psycho replied to lcy's topic in PHP Coding Help
Did you read the tutorial I linked to? If you read that it should get you started. To export to any particular file type you will need to know the format of that file and write a file in that format. If you can't follow the tutorial to get the basics, I'm not sure how we can help you in a forum. If, however, you have specific questions about things int he tutorial, then by all means ask. -
I would use an array. Based upon your code I suspect there may be multiple types of levels (experience, energy, etc.). So this function can be used for multiple levels. Just create an array for each level type, as in the example. Then pass the array and the user points for that level to the function. You will have an object returned with two value the current level name and the points needed to achieve the next level. <?php $exp_levels = array( 'Level 1' => 0, 'Level 2' => 100, 'Level 3' => 300, 'Level 4' => 1000, 'Level 5' => 5000 ); function currentLevel($levelAry, $userPoints) { $level->name = ''; $level->pointsToNext = 0; foreach($levelAry as $levelName => $levelPoints) { if ($userPoints<$levelPoints) { $level->pointsToNext = ($levelPoints-$userPoints); return $level; } $level->name = $levelName; } //User is over maximum return $level; } $experience = 525; $userLevel = currentLevel($exp_levels, $experience); echo "User is at level " . $userLevel->name . "<br>"; echo "Points to next level " . $userLevel->pointsToNext; //Output: //User is at level Level 3 //Points to next level 475 ?>
-
Even easier, don't allow the user to enter in their domain at all, just the username portion of the email. Then in your code, assume that the domina is the one you specify. On the actual form, display the domain name to the right of the input field so the user understands that the domain is assumed <input type="text" name="uname" > @thextremezik.com Then just validate that the value has letters, numbers, undercore, dash, plus sign & periods. Of course the value can't begin or end with a period or have two periods in succession.
-
@gr1zzly, The file is being "included" from the client browser from within script tags. Therefore the file must be within a web accessible folder.
-
I don't think there is a solution for this. If you have a file in a publicly accessible directory there is no foolproof way to secure it. The problem is that the file must be publicly accessible because it needs to be accessible to the user's browser - and I'm no expert on Flash, but I suspect the file may also be getting saved to the user's cache. There are plenty of tricks/hacks that you could use (obfuscating the code, checking headers, etc). But, it will not be foolproof, and anyone who really wants the content will be able to get it.
-
What is exporting .php file to other types of file extension?
Psycho replied to lcy's topic in PHP Coding Help
You would simply use PHP to write to a file for most of those. See tutorial below. Based upon the file type you would prepare the data differently: e.g., a CSV file you would write as comma separated, and HTML file would have HTML tags, etc. Other file types, such as PDF, can be generated using PHPs build in PDF library or even third party tools. Then others may not have a direct PHP solution. http://www.tizag.com/phpT/filewrite.php -
When you say you want users to be able to access with a "regular browser", but you then want to reject their submission, that makes no sense to me. Anyway, you might be able to utilize the CSS "@media" rule to make it such that the form is only displayed for mobile browsers int he first place since there is a type of "handheld" that is recognized. Basically the CSS can specify different style sheet properties based on the media type of the output. So, for a "handheld" type you would set the display property of the form to be displayed, if not a handheld then make the display none.
-
First you say 5 characters, then you say 7. From your examples I assume you mean seven. Are ALL of the characters in your language going to be 7 characters? If so, just multiple the length by 7. Your function is quite inefficient to begin with. Here is a function I use to do the same thing: function subStringWords($string, $length, $ellipse='...') { if (strlen($string) <= $length) { return $string; } return array_shift(explode("\n", wordwrap($string, $length))) . $ellipse; } A simple modification will have it treat 7 characters as a single character, like so function subStringWords($string, $length, $ellipse='...') { $length = $length * 7; if (strlen($string) <= $length) { return $string; } return array_shift(explode("\n", wordwrap($string, $length))) . $ellipse; } Now, that won't work if all elements are not represented by 7 characters.
-
can't people tell the difference between php and html ?
Psycho replied to saltedm8's topic in PHPFreaks.com Website Feedback
http://en.wikipedia.org/wiki/Markup_language http://en.wikipedia.org/wiki/Programming_language I think the disconnect here is that most people who understand programming are sometimes frustrated (myself included) by the fact that many lay people correlate a "markup language" with programming. The concept of a "webmaster" has also contributed to the denigration of true web-based application developers. Many people with the ability to use a WYSIWYG editor like Dreamweaver or even Word, considered themseleves a programmer - without even knowing basic HTML.