newbtophp
Members-
Posts
631 -
Joined
-
Last visited
Everything posted by newbtophp
-
Hey!, Just looking for some advice on developing a voting/rating algorithm. What is the most effective way to develop this? Right now, I am using minimalistic/very simple algorithm, I have two columns: number_of_votes and total_vote, and the score = number_of_votes/total_vote Problem is, it can be easily skewed if their are a low number of votes (1 vote of 5 will boost the score to 5). PS: They can vote from 1-5 (the max the score can be is 5) Thanks guys!
-
Which is more reliable (functionality wise - not compatibility wise). Using Javascript (new Date(); function to detect user/visitor time automatically) or PHP's (Date and Time extension - DateTime:: - where the user/visitor selects their timezone themselfs) To retrieves the users/visitors time?
-
Crisis? when using cookies or not using logout.php
newbtophp replied to newbtophp's topic in PHP Coding Help
loginTime is set using php's time()... so for checking the total users online, would the following work? <?php $time = time(); $result = mysql_query("SELECT user FROM site_table WHERE loginTime > ($time - ( 15 *60 ))"); //mysql_num_rows etc.. Tested that and that works. solved. cheers MadTechie -
Crisis? when using cookies or not using logout.php
newbtophp replied to newbtophp's topic in PHP Coding Help
loginTime is set using php's time()... so for checking the total users online, would the following work? <?php $time = time(); $result = mysql_query("SELECT user FROM site_table WHERE loginTime > ($time - ( 15 *60 ))"); //mysql_num_rows etc.. -
Crisis? when using cookies or not using logout.php
newbtophp replied to newbtophp's topic in PHP Coding Help
Ok great, but one thing wouldn't now( ) be UNIX_TIMESTAMP() instead or $time ( and $time is assigned to $time = time(); )? -
Crisis? when using cookies or not using logout.php
newbtophp replied to newbtophp's topic in PHP Coding Help
Thanks im going to try it, but wouldn't that mean the loginTime is more then 15 minutes, don't we want it to be loginTime <= 15 (to be within 15 minutes?) or am I totally confused and really dumb -
Crisis? when using cookies or not using logout.php
newbtophp replied to newbtophp's topic in PHP Coding Help
Ok I've deleted the isOnline as its uneeded. So now I have loginTime which is UPDATEd with the current time() (timestamp) upon page load (its added at the top of every page within an include). How would I determine if a specific user is online, how would the query be (im guessing it would be structured like the example below but not sure how the WHERE bit will be)? SELECT user FROM site_table WHERE loginTime IS WITHIN 15 MINUTES FROM CURRENT TIME AND user = 'tester' -
Hey! I have a table...with a column isOnline which is set to 1 when logging in (using login.php)...and 0 when logging out (logout.php), its how I determine whos logged in and whos not (in statistics etc.) Now the problem is if they dont have the remember me enabled..and don't log themselfs out via logout.php (which sets the isOnline to 0)...and close their browser the $_SESSIONS's get destroyed (which means their physically not logged in)...and their isOnline remains at 1 (even though their logged out) Another problem..is if they login with remember me enabled (as they want to remain logged in)....and close their browser or whatever, isOnline will still remain as 1 (theirfore others will think their online). For your info: In login.php I do an UPDATE query adding the current time generated by time() into the loginTime column...and also setting isOnline to 1. So my question is how can I overcome this, I have the isOnline (1 = logged in, 0 not logged in) and loginTime (which contains the login timestamp)? Cheers
-
friendly bump lol
-
Hi, Is this the correct way to go by setting cookies for my login 'remember' functionality?, I've posted the relevant login and logout code. Login: <?php session_start(); //some code... if (isset($_POST['remember'])) { $expire = time() + 1728000; // Expire in 20 days $site_domain = 'phpfreaks.com'; //example $_SESSION['username'] = $_POST['username']; //don't worry this has been validated $username = $_SESSION['username']; //some sql query to fetch code.. $code = $row['code']; setcookie('username', $username, $expire, NULL, ".$site_domain", NULL, TRUE); setcookie('code', $code, $expire, NULL, ".$site_domain", NULL, TRUE); } ?> Logout: <?php session_start(); if (isset($_COOKIE['username'])) { $expire = time() - 1728000; // Expire in 20 days $site_domain = 'phpfreaks.com'; //example $username = $_SESSION['username']; //some sql query to fetch code.. $code = $row['code']; setcookie('username', $username, $expire, NULL, ".$site_domain", NULL, TRUE); setcookie('code', $code, $expire, NULL, ".$site_domain", NULL, TRUE); } unset($_SESSION['username']); $_SESSION = array(); session_destroy(); ?> Please tell me if it looks good to go and/or any improvements. PS: I want it accessible on all areas of the domain (including subdomains and paths etc.), and HTTP ONLY (so js can't access it) - I believe I've set the right parems?
-
so you mean this is wrong even if it works well on my part? I added this on the above script: $lang= curPageURL(); $query = parse_url($lang, PHP_URL_QUERY ); if ($query=="lang=zh-hans") Your going about it the long way. Whats wrong with.... if ($_GET['lang'] == 'zh-hans') { // do whatever. } Of course, you should also check lang is set first.... if (isset($_GET['lang'] && $_GET['lang'] == 'zh-hans') { // do whatever. } This is why I asked what exactly you where planning on doing with the data in my first reply. There really is no need to parse the url yourself. Your missing the closing parethisis for the isset on your code.
-
.. on the same line or throughout the string? Throughout so if theirs no <?php opening tag before it remove it.
-
Never mind solved it using if statements
-
<?php $newphrase = 1234567; preg_match_all('~\d{1}~', $newphrase, $a); echo max($a[0]); ?>
-
I'm trying to create a function where you specify the $points it will then do some mathematical stuff with the $points (explain later) an return an array containing the $rank and $level. The mathematical stuff: It starts at 99 and when it reaches +199 it changes the key of the array. I'm not sure how to describe this theirfore i'll just provide examples: Example 1: If $points <= 99 It will return an array containing $ranks[0] and $levels[0], would be the following: return array('Peon', 0); Example 2: If $points >= 100 && $points <= 299 It will return an array containing $ranks[1] and $levels[1], would be the following: return array('Grunt', 1); Example 3: If $points >= 300 && $points <= 499 It will return an array containing $ranks[2] and $levels[2], would be the following: return array('Berserker', 2); etc.. until it reaches the 7th key of the $ranks/$levels array Heres my code: <?php function rank($points){ //their are 0-7 levels $levels = range(0, 7); //7 ranks $ranks = array('Peon', 'Grunt', 'Berserker', 'Tauren', 'Spirit Walker', 'Wind Rider'); for(...) { return array($rank, $level); } } ?>
-
I have an idea, which I'm trying to realise, im using the time() function to store the timestamp within my db...and within the db I have a timezone column (which contains the timezone selected by that user). So I'd like to display $row['timestamp'] (the stored timestamp generated by time()) to the specified timezone, how would that work? <?php //$timestamp = timestamp generated by the time() function //$timezone = the timezone to convert $timestamp too function convert_time($timestamp, $timezone) { //$new_timestamp = do something to adapt $timestamp to $timezone //return the formatted/readable date... return date('D M Y H:i', $new_timestamp); } ?>
-
I meant like is their something I can do so in the furture if I changed the way the seo urls where, I can easily change the urls within the code?, I can use variables - within a global/config file, but is their a better solution (more generic?)
-
Is their something I can do in PHP (like some sort of function/config/array etc...) which would make the following process easier (examples appreciated)... I have an .htaccess file where im rewriting urls to seo friendly ones...now in the PHP script is their something I can place for urls are meant to be displayed/linked (like some sort of placeholder) which makes it easier for me to modify the urls within the PHP script, without constantly editing countless php sourcecode to just change the url? Example scenario: Say I had a php file (called submit.php): <?php echo 'Hey! Thanks for submiting the form, <a href="submit.php?form">click here</a> to go back!'; ?> and my rewrite rule for submit.php?form was: /form How would I easily change the url within submit.php without editing submit.php directly?
-
Gr8 Wolphie that worked
-
Im trying to make the first parem the array key, and then that value of that array is extracted within the function, refer to the first post. Cheers
-
Im using func_get_args, but it gives an error?: Too few arguments?, when its correct (as the number of %s = the number of values within $args) <?php function sprintify() { global $urls; $args = func_get_args(); $input = $args[0]; unset($args[0]); return sprintf($urls[$input], implode(', ', $args)); } echo sprintify('default', 46, 464, 46); /* For your information: $urls['default'] = '%s/%s/%s'; */ ?>
-
so use (.+?) As the + matches only if it contains 1 character or more right? (correct me if im wrong)
-
Its their but the bbcode got parsed (view src to see lol), so i'll wrap it in a code tag so it doesnt: [b](.+?)[/b] //or [b](.*?)[/b] Which would be better within a preg_replace? (for a simple bbcode parser)
-
Ok thanks Alex! /Solved
-
So what about: (.+?) or (.*?) Which would be the best in this situation?