One thing I see is that you do a lot of database queries, some of them in loops so that they may occur many times more. A little preg_match_all() on the file shows 51 separate SELECT queries:
[1]"SELECT id,unix_timestamp(date) as datets,uid_from,what,amt,what_req,amt_req,auth FROM $logtrade_table WHERE uid_to=$user and hide=0 and auth=0 ORDER by date DESC"
[2]"SELECT id,unix_timestamp(date) as datets,uid_from,what,amt,what_req,amt_req,auth FROM $logtrade_table WHERE uid_to=$user and hide=0 and auth=0 ORDER by date DESC"
[3]"SELECT id,unix_timestamp(date) as datets,uid_to,what,amt,what_req,amt_req,auth,hide FROM $logtrade_table WHERE uid_from=$user ORDER by date DESC limit 50 "
[4]"SELECT pic, name FROM user WHERE uid=$uid"
[5]"SELECT pic, name FROM user WHERE uid=$uid"
[6]"SELECT $col FROM $users_table WHERE uid=$user"
[7]"SELECT cup,unix_timestamp(date) as date,win FROM $history_table WHERE uid=$user ORDER BY date DESC LIMIT $num"
[8]"SELECT unix_timestamp(date) as date,uid_to,what,amt FROM $logsend_table WHERE uid_from=$user"
[9]"SELECT unix_timestamp(date) as date,uid_from,what,amt FROM $logsend_table WHERE uid_to=$user"
[10]"SELECT unix_timestamp(date) as date,reg_add,lj_bonus,ic_bonus,hu_bonus,rod_bonus,chr_bonus,val_bonus,bug_bonus,camp_bonus,ch_bonus,coin_bonus,bill_bonus,bd_bonus,bb_bonus,cookie_bonus,metal_bonus,gem_bonus FROM $bonus_table WHERE uid=$user"
[11]"SELECT unix_timestamp(NOW()) - unix_timestamp(last_logon_credit)
from $users_table where uid=$user"
[12]"SELECT sum($prize) FROM $users_table"
[13]"SELECT sum(new) FROM $cpa_table WHERE uid=$user and notified='0'"
[14]"SELECT uid_from,notified_to FROM $logtrade_table WHERE uid_to=$user and notified_to='0'"
[15]"SELECT id,uid_from,what,amt FROM $logsend_table WHERE uid_to=$user and notified='0' and trade=0"
[16]"SELECT sum(coupon1) FROM $users_table WHERE uid=$user and coupon1_notified='0'"
[17]"SELECT sum(survey1) FROM $users_table WHERE uid=$user and survey1_notified='0'"
[18]"SELECT count(id) FROM $refs_table WHERE ruid=$user and notified='0'"
[19]"SELECT iuid FROM $invites_table WHERE uid=$user"
[20]"SELECT uid FROM $users_table ORDER BY $type DESC"
[21]"SELECT uid, $type FROM $users_table ORDER BY $type DESC LIMIT $start,$offset"
[22]"SELECT uid, $type FROM $users_table where uid=$user"
[23]"SELECT uid, $type FROM $users_table WHERE uid IN ('"
[24]"SELECT cups_played FROM $users_table WHERE uid=$user limit 1"
[25]"SELECT cents FROM $users_table WHERE uid=$user limit 1"
[26]"SELECT money_bought FROM $users_table WHERE uid=$user limit 1"
[27]"SELECT regular_intervals FROM $users_table WHERE uid=$user limit 1"
[28]"SELECT invites FROM $users_table WHERE uid=$user limit 1"
[29]"SELECT invite_days FROM $users_table WHERE uid=$user limit 1"
[30]"SELECT impressions FROM $users_table WHERE uid=$user limit 1"
[31]"SELECT cpa_offers FROM $users_table WHERE uid=$user limit 1"
[32]"SELECT ref FROM $users_table WHERE uid=$user limit 1"
[33]"SELECT last_logon_credit FROM $users_table WHERE uid=$user limit 1"
[34]"SELECT last_logon FROM $users_table WHERE uid=$user limit 1"
[35]"SELECT active FROM $users_table WHERE uid=$user limit 1"
[36]"SELECT sid FROM $users_table WHERE uid=$user limit 1"
[37]"SELECT id FROM $users_table WHERE uid=$user limit 1"
[38]"SELECT created FROM $users_table WHERE uid=$user limit 1"
[39]"SELECT $param FROM $users_table WHERE uid=$user limit 1"
[40]"SELECT notifications FROM $users_table WHERE uid=$user limit 1"
[41]"SELECT notification_days FROM $users_table WHERE uid=$user limit 1"
[42]"SELECT app_installs FROM $users_table WHERE uid=$user limit 1"
[43]"SELECT country FROM $users_table WHERE uid=$user"
[44]"SELECT uid, unix_timestamp(date), city_province, name, comments from $winners_table where verified=1 order by id desc limit 1"
[45]"SELECT pic FROM user WHERE uid=$uid"
[46]"SELECT win_nothing,win_nothing_last from $users_table where uid=$user"
[47]"SELECT count(uid) FROM $users_table where unix_timestamp(NOW()) - unix_timestamp(last_logon) < $online_time"
[48]"SELECT id FROM $refs_table WHERE uid=$person and ruid=$referer"
[49]"SELECT active FROM $users_table WHERE uid=$user limit 1"
[50]"SELECT unix_timestamp(NOW()) - unix_timestamp(last_logon_credit)
from $users_table WHERE uid=$user"
[51]"SELECT iuid,uid FROM $invites_table WHERE uid=$user"
One thing that probably needs to be done is to figure out how much effort is being duplicated among them, and consolidating multiple queries into single queries. Even if an individual query becomes more complicated, 1 complex query that replaces 10 simple queries will likely save a lot of processing.
Now to ask me to wade through all that code and actually figure out what could/should be combined is a lot more effort than I'm ready to do [for free] at this time. 😉