Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-21-2008, 07:28 PM php help
Super Talker

Posts: 113
Name: Paul
Trades: 0
I had a php programmer integrate my forum with my video ripping site which basically set a 20mb download limit for members of the forum and they earn an extra 2mb per post they make within the forum, I'd like to increase this limit from 2mb to 5mb but I cant get hold of him despite sending numerous emails, he always said it was easy to change but I dont understand php so for me its hard. I think I've found the section of code I need to change but could someone explain what this section of code means:


$numPosts = mysql_num_rows(mysql_query("SELECT poster_id FROM phpbb_posts WHERE poster_id = '".$resSess['session_user_id']."'"));

//Setup the multiplier of posts with Mb.
$mult = $numPosts*2*1024*1024;
$limit = $limit + $mult;

//$lim = ($limit/1024/1024);

//echo round($lim,3)."Mb";
//exit;

$goBACK = "<a href='index.php' style='font-weight:bold; font-size:12px;'>Go Back</a>";
}
if(!$res['username'] || $res['username'] == "Anonymous"){
$limit = $max_guest_download*1024*1024;
$selRemain = mysql_query("SELECT SUM(size) AS totalDownload FROM downloads WHERE ip = '".$ip."' AND user_id = '0' AND date >= '".$oneMonthAgo."'");
$resRemain = mysql_fetch_array($selRemain);

$totalDownload = $resRemain['totalDownload'];
$userID = "0";
$type = "GUEST";
$goBACK = "<a href='../forums' style='font-weight:bold; font-size:15px;'>Register to our forums now</a> <span style='font-size:15px;'>and get <b>".$max_regis_download." Mb</b> of FREE downloads every <b>".$timeLimitation." day(s)</span></b>";
fattony is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-21-2008, 08:17 PM Re: php help
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP Code:
$mult $numPosts*2*1024*1024
There it is, it's the "2" in the line.
2 * 1024 = 2 Kilo Octet
2 * 1024 * 1024 = 2 Mega Octet

As for explaining the code: first, the number of post of the user is fetched:
PHP Code:
$numPosts mysql_num_rows(mysql_query("SELECT poster_id FROM phpbb_posts WHERE poster_id = '".$resSess['session_user_id']."'")); 
Then, the script computes what "extension" of the limit the user is allowed to have
PHP Code:
$mult $numPosts*2*1024*1024;
$limit $limit $mult
And then, the script does something with those infos, but the code being cut-off, I cannot say more...
I think you have badly cut the file (to preview it to us) , because the } sign indicate that all of this is done into a "if" block, or a loop maybe, but I think more likely a if.
Because the rest of the script is related to an not logged user, or unknown user that is treated as a guest.

But 99% chances that simply changing that 2 in 5 on the 3rd line will do what you are looking for.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-21-2008 at 08:24 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-21-2008, 09:01 PM Re: php help
Super Talker

Posts: 113
Name: Paul
Trades: 0
Thanks for that i thought it was something to do with this:

$mult = $numPosts*2*1024*1024;

But I couldn't work out where the *1024*1024 came into it, I'll give it a go, and yes I probably did cut the code badly I just wanted to preview the section where I thought the edit needed to be made, thanks for taking the time to try and explain the code, I'd love to learn PhP it seems such a powerful language
fattony is offline
Reply With Quote
View Public Profile
 
Old 06-21-2008, 09:10 PM Re: php help
Super Talker

Posts: 113
Name: Paul
Trades: 0
I have copied pretty much all the code here does this help, just making sure I'm editing the right bit thats all:

//Get limits
$selSess = mysql_query("SELECT * FROM phpbb_sessions WHERE session_id = '".in($_COOKIE['phpbb3_gd2po_sid'])."'");
$resSess = mysql_fetch_array($selSess);

$sel = mysql_query("SELECT * FROM phpbb_users WHERE user_id = '".$resSess['session_user_id']."'");
$res = mysql_fetch_array($sel);

$month = 86400*$timeLimitation;
$oneMonthAgo = time()-$month;

//echo $res['username'];
//echo "<hr>";
//echo $resSess['session_id'];
//echo "<hr>";
//exit;

if($res['username'] != "Anonymous" && $res['username'] != ""){
$limit = $max_regis_download*1024*1024;
$selRemain = mysql_query("SELECT SUM(size) AS totalDownload FROM downloads WHERE user_id = '".$resSess['session_user_id']."' AND date >= '".$oneMonthAgo."'");
$resRemain = mysql_fetch_array($selRemain);
$totalDownload = $resRemain['totalDownload'];
$userID = $resSess['session_user_id'];
$type = "FORUM MEMBER";

//Get user's total number of posts

$numPosts = mysql_num_rows(mysql_query("SELECT poster_id FROM phpbb_posts WHERE poster_id = '".$resSess['session_user_id']."'"));

//Setup the multiplier of posts with Mb.
$mult = $numPosts*5*1024*1024;
$limit = $limit + $mult;

//$lim = ($limit/1024/1024);

//echo round($lim,3)."Mb";
//exit;

$goBACK = "<a href='index.php' style='font-weight:bold; font-size:12px;'>Go Back</a>";
}
if(!$res['username'] || $res['username'] == "Anonymous"){
$limit = $max_guest_download*1024*1024;
$selRemain = mysql_query("SELECT SUM(size) AS totalDownload FROM downloads WHERE ip = '".$ip."' AND user_id = '0' AND date >= '".$oneMonthAgo."'");
$resRemain = mysql_fetch_array($selRemain);

$totalDownload = $resRemain['totalDownload'];
$userID = "0";
$type = "GUEST";
$goBACK = "<a href='../forums' style='font-weight:bold; font-size:15px;'>Register to our forums now</a> <span style='font-size:15px;'>and get <b>".$max_regis_download." Mb</b> of FREE downloads every <b>".$timeLimitation." day(s)</span></b>";
}
//print_r ($resRemain);
//echo $totalDownload;
//echo "<hr>";
//echo $limit;
//exit;
if($totalDownload >= $limit){
echo "<font color='red'><b>WARNING:</b> You have exceeded your download limit for your <b>".$type."</b> account.<br />You may only download: <b>".number_format($limit/1024/1024,3)." Mb</b> every <b>".$timeLimitation." day(s) concidering the number of posts you have made. You will get 2Mb extra download for every new message posting activity on our forums.</b>.<br />You have already downloaded <b>".number_format($totalDownload/1024/1024,3)." Mb</b> in the past <b>".$timeLimitation." day(s)</b>.<p>".$goBACK."</font>";
exit;

any idea what the 1024/1024,3 part means on the 3rd from last line

Thanks

Paul

Last edited by fattony; 06-21-2008 at 09:14 PM..
fattony is offline
Reply With Quote
View Public Profile
 
Old 06-21-2008, 09:46 PM Re: php help
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Originally Posted by fattony View Post
Thanks for that i thought it was something to do with this:

$mult = $numPosts*2*1024*1024;

But I couldn't work out where the *1024*1024 came into it, I'll give it a go, and yes I probably did cut the code badly I just wanted to preview the section where I thought the edit needed to be made, thanks for taking the time to try and explain the code, I'd love to learn PhP it seems such a powerful language
It's math... A bit can be 0 or 1, and in base 10 it's 2 factor 10: 1024...
1024 octets makes 1 Ko
1024 Ko makes 1 Mo
so, 2 * 1024 * 1024 means 2 Mo...

Quote:
any idea what the 1024/1024,3 part means on the 3rd from last line
Debugging code...
It was to get back the number of message multiplied by the amount in Mo.
I think your dev wanted to check if it worked right.
Everything between /* and */ are multilines comments.
// denote a comment too, but only from his position to the end of the line.
And the ",3" is in fact a parameter sent to the round function.
http://www.php.net/manual/en/function.round.php
Quote:
float round ( float $val [, int $precision ] )
Means that the function round() take a number with a decimal as first parameter, and that the second paramter is optional, but can be specified.
In that case, it asked the function to round to 3 numbers after the comma.
for example:
PHP Code:
$val=3.14159;
echo 
round($val,3); 
will output
Code:
3.142
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-21-2008 at 09:49 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-22-2008, 06:31 AM Re: php help
Super Talker

Posts: 113
Name: Paul
Trades: 0
thanks very much I appreciate your help
fattony is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69358 seconds with 12 queries