Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
FYI: You can cut your code nearly in half by making the patterns case insensitive: Instead of "/\[b\](.*?)\[\/B\]/", "/\[b\](.*?)\[\/b\]/", Use this, with the "i" parameter to indicate the patwtern should be case insensitive. "/\[b\](.*?)\[\/b\]/i",
-
Why is date('F', $n) returning December only?
Psycho replied to lordvader's topic in PHP Coding Help
You are correct that the second parameter is a timestamp and that a timestamp is supposed to be the number of seconds past January 1, 1970 midnight. However, if the OP was to follow your logic I suspect he is scratching his head because his results are returning 'December' - not January. I suspect this has to do with Daylight savings being in effect. -
Are you running this in a test environment or on a server hosted by a 3rd party? I found that the provider 1and1 does NOT support the socket functions after I transferred a site to them.
-
Looks OK to me, but it's a waste of extra lines. I'd just change the function to this function delete_check() { return confirm("Are you sure you want to delete that?"); } Or if you really want to clean it up don't use a function at all: <a href="thepage.php" onclick="return confirm('Are you sure you want to delete that?');">the link</a> Depending on your need this *may* be better. I'd incorporate the confirm into the link if it is only used on the page in one or two places. But, if multiple links need the same confirmationthen I would go with a function to make it easier to modify the process later on.
-
Assuming your var is named value: value = '0000' + value; value = value.substr(value.length-4, 4);
-
What is the game? Chances are there is a class readily available to query the game server and get that data.
-
click counter not working properly. *please help*
Psycho replied to madhead29's topic in PHP Coding Help
I think you should take a different approach to determining "which" links have been clicked - because you will need to keep a record of each uniqe link. In fact you don't need to keep a counter variable since you can easily get the count of "clicks" based upon the number of records. I'm not going to go through the code above and rewite it all, btu I will provide some mock code: First I would have a table with the following fields: user_clicks - ipaddress - link_id Then when a user clicks a link I would simply take the ID off of the query string and test if it is in the table for the current user's IP. If no, add a new record, if yes do nothing. <?php $query = "SELECT * FROM user_clicks where ip_address='$userIIP' AND link_id='$linkID'"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result)==0) { $query = "INSERT INTO user_clicks (ip_address, link_id) VALUES('$userIIP','$linkID')"; $result = mysql_query($query) or die (mysql_error()); } ?> You could then get the number of clicks for an IP address with the following: <?php $query = "SELECT COUNT(*) FROM user_clicks where ip_address='$userIIP' GROUP BY ip_address"; $result = mysql_query($query) or die (mysql_error()); $record = mysql_fetch_array($result); $count = $record[0]; echo "The user has click $count unique links"; ?> -
This uses a slgihtly different method, but works in FF and IE and gives you the time the mouse was down. Change 'interval' to the unit of time that you need to capture (100 = 10ths of a second): <HTML> <HEAD> <script type="text/javascript"> var interval = 100; //milliseconds var mdown = false; var seconds = 1000/interval; function init() { document.onmousedown = function (e) { mdown = true; changeState(mdown); startTimer(0); } document.onmouseup = function (e) { mdown = false; changeState(mdown); } } function changeState(state) { document.getElementById('mdstate').innerHTML = state; } function startTimer(timeDown) { if (mdown) { document.getElementById('mdtime').innerHTML = Math.round(timeDown/1000*seconds)/seconds; setTimeout('startTimer('+(timeDown+interval)+')', interval); } } </script> </HEAD> <BODY onload="init();"> Mouse Down State: <span id="mdstate"></span><br> Mouse Down Time: <span id="mdtime"></span> </BODY> </HTML>
-
So, put it at the top of the page. Not trying to be an a**, but it should be that simple.
-
Hmmm, there seems to be something missing. I have pasted the code above into an HTML page (replacing the PHP loops with test OPTION entries) and it doesn't work for me. Can you post a working example?
-
Not tested <script type="text/javascript"> document.write('<select name="page" onchange="jumptopage(this.value);">'); for (i=1; i<Math.ceil(galleryarray.length/totalslots)+1; i++) { document.write('<option value="'+i+'">Page '+i+'</option>'); } document.write('</select>'); </script>
-
Why use javascript? Just set the field to readonly: <div class="editRightForm"> <input type="text" class="itemEditForm02" readonly="readonly" name="ProductNo" value="<?php echo $row['ProductNo'];?>" /> </div> If you need to be able to change the field back and forth from readonly, then you would do that with javascript in this manner (although not totally necessary, it would be best to give the field an ID): document.getElementById('fieldID').readOnly = true; //or false
-
What do you want to happen when the user clicks the back button? What you want will determine the solution.
-
1. Remove the onclick="testCreditCard();" trigger in the submit button. 2. Add a onsubmit="testCreditCard();" trigger in the FORM tag. 3. Change the testCreditCard () function to return a true/false response as follows: function testCreditCard () { if (checkCreditCard (document.getElementById('payee_cardNum').value,document.getElementById('payee_cardType').value)) { alert ("Credit card has a valid format"); return true; } else {alert (ccErrors[ccErrorNo])}; return false; }
-
I'd use this one liner with an IF statement: $query = $db->execute("update `players` set hp = IF((hp + 10)>maxhp, maxhp, (hp + 10))" );
-
There is absolutely no way to ever know if a user has closed the browser. You can supply a logout button/link, but many, if not most, users will not use it. They wil instead close the browser window when they are done. As I already stated before you can't know if the user has closed the browser window or if they are simply still viewing the last page accessed. From the server side you can only know the last accessed time of the user. That is why YOU need to set a time limit to determine if the user is still online.
-
Your question is not making sense as posed. You have to have some value that you are comparing against which would lead to a simple query such as: SELECT * FROM `sessions` WHERE `sport` = $somevalue If you are wanting to JOIN the two tables then what is the supplied value you are going to search on - sportsname? In that case the query would look like this: SELECT * FROM `sessions` JOIN `sports` ON sessions.sport = sports.sportsid WHERE `sportname` = $searchvalue However, I would recommend changing the value of `sport` to `sportid` in the `sessions` table, because that is what it is. makes it a lot easier to coordinate the tables.
-
It's right at the top of the page in the manual for that command. http://us.php.net/manual/en/ref.mail.php
-
Cookies are not going to do anything to help you in this situation as they are stored client-side. You need to do as BlueSkyIS explained. On any page access update the user record with a timestamp. Then, you need to decide at what time period the user is no longer "logged in", because you have no way of knowing if the user closed their browser window and shut down the computer or if they are just takign their time reading the content on a page. Personally, I would go with 20 minutes. So, if the user's last activity was within 20 minutes then you show them as "online". Otherwise, if their last activity was today (but not within 20 minutes) then you would show them as logged in today. Etc.
-
I have not encountered this in my 6 years of PHP coding (SESSIONS)
Psycho replied to 2levelsabove's topic in PHP Coding Help
Cookies disabled on the client? The client must accept the cookie with the session ID for the session to be rememebred from page to page. Check the cookies folder to see if it is even getting saved. Or, is this problem persistent across many computer and browsers. What have you tried so far? -
Just found an error in the code I posted above: This line $return_vals[$list_item] = $category; Should be $return_vals[$list_item][] = $category;
-
Correction to Reply#1. I unintentionally picked up a modified function that I was testing with and that RegEx is not correct. Here is the correct function: <?php function is_email($email) { $formatTest = '/^[-\w+]+(\.?[-\w+])*@[-a-z\d]{2,}(\.?[-a-z\d]{2,})*\.[a-z]{2,6}$/i'; $lengthTest = '/^(.{1,64})@(.{4,255})$/'; return (preg_match($formatTest, $email) && preg_match($lengthTest, $email)); } // NOTES: // // Format test // - Username accepts: 'a-z', 'A-Z', '0-9', '_' (underscore), '-' (dash), '+' (plus), & '.' (period) // Note: cannot start or end with a period (and connot be in succession) // - Domain accepts: 'a-z', 'A-Z', '0-9', '-' (dash), & '.' (period) // Note: cannot start or end with a period (and connot be in succession) // - TLD accepts: 'a-z', 'A-Z', & '0-9' // // Length test // - Username: 1 to 64 characters // - Domain: 4 to 255 character ?>
-
<?php function match_categories($list, $cat) { //Create the arrays $list_array = explode("\n", $list); $cat_array = explode("\n", $cat); //clean the data foreach ($list_array as $key => $value) $list_array[$key] = trim($value); foreach ($cat_array as $key => $value) $cat_array = trim($value); $return_vals = array(); //Search each category for each list item foreach ($cat_array as $category) { foreach ($list_array as $list_item) { if (strpos($category,$list_item)) { $return_vals[$list_item] = $category; } } } } $found_categories = match_categories($_POST['list'], $_POST['cat']) ?>
-
database gotcha new code any inprovements welcome
Psycho replied to redarrow's topic in PHP Coding Help
But, the value gets overwritten on the very next line of code. So, the line $number=mysql_real_escape_string($_POST['number']); is of no use. -
database gotcha new code any inprovements welcome
Psycho replied to redarrow's topic in PHP Coding Help
I see problems right at the beginning and stopped looking through the rest of the code. <?php // post number randomly $number=mysql_real_escape_string($_POST['number']); // make number round. $number=rand(000000,999999); // if a number isset........ if(isset($number)){ ?> That makes no sense. The code first sets $number based upon $_POST['number'] Then regardless if there is any value or not it is reset to rand(000000,999999) Then there is this IF statement if(isset($number)) But that will ALWAYS be true duve to the random number assigned in the previous step. Seems to be some logic problems here.