Bradley99 Posted January 24, 2011 Share Posted January 24, 2011 So basically, My Bulletfactory page is playing up. Every 30 minutes the bulletfactory should produce bullets, it is producing the bullets fine, but only when someone views the page (after 30 minutes is up). If there any kind of PHP refresh for this? Or do i just use normal refresh? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/ Share on other sites More sharing options...
bh Posted January 24, 2011 Share Posted January 24, 2011 Hi, with meta-refresh tag? Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164606 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 That's what I've done so just waiting to see if it works Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164609 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Didnt' work This is the PHP code part of the page: <?php session_start(); include_once"includes/db_connect.php"; include_once"includes/functions.php"; include_once "click_limit.php"; logincheck(); $username=$_SESSION['username']; $query=mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch=mysql_fetch_object($query); $query_bf=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'"); $fetch_bf=mysql_fetch_object($query_bf); if (strtolower($fetch_bf->owner) == (strtolower($fetch->username))){ require_once"bulletCP.php"; exit(); } $new_time=time()+1800; $up=mysql_fetch_object(mysql_query("SELECT * FROM site_stats WHERE id='1'")); $a=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'"); $b=mysql_fetch_object($a); $user=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$b->owner'")); //$minus=$user->money - 1000; if ($user->money < 1000){ mysql_query("UPDATE bf SET owner='None', producing='No' WHERE id='$b->id'"); $crap=1; } if ($fetch_bf->time < time() && $fetch_bf->producing == "Yes" && $crap != "1"){ mysql_query("UPDATE bf SET stock=stock+750 WHERE `location`='$fetch_bf->location'"); mysql_query("UPDATE bf SET `time`='$new_time' WHERE `location`='$fetch_bf->location'"); mysql_query("UPDATE users SET `money`=`money`-75000 WHERE username='$b->owner'"); } if ($fetch->last_bullet > time()){ $left = " ".maketime($fetch->last_bullet).""; echo "You have dona a bullet deal recently, you have to wait for $left seconds before you can do another!"; exit(); } if (strip_tags($_POST['check']) && (strip_tags($_POST['amount']))){ $amount=intval(strip_tags($_POST['amount'])); if ($amount == 0 || !$amount || ereg('[^0-9]',$amount)){ print "You cant buy that amount."; }elseif ($amount != 0 || $amount || !ereg('[^0-9]',$amount)){ $costs = $fetch_bf->price * $amount; if ($costs > $fetch->money){ echo "You do not have enough money"; } elseif ($costs <= $fetch->money){ $nmoney=$fetch->money - $costs; if ($fetch_bf->stock < $amount){ echo "Not that many bullets in the store."; } elseif ($amount <= $fetch_bf->stock){ $nbullets=$fetch->bullets + $amount; $nstock = $fetch_bf->stock - $amount; ///IF THERE IS NOOOOO OWNER if ($fetch_bf->owner == "0"){ mysql_query("UPDATE users SET bullets='$nbullets', money='$nmoney' WHERE username='$username'"); mysql_query("UPDATE bf SET stock='$nstock', profit='$costs' WHERE location='$fetch->location'"); echo "Bullets successfully bought."; ////IF THERE IS A OWNER }elseif ($fetch_bf->owner != "0"){ $fetch_owner=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$fetch_bf->owner'")); $new_owner=$fetch_owner->money + $costs; mysql_query("UPDATE users SET bullets='$nbullets', money='$nmoney' WHERE username='$username'"); mysql_query("UPDATE users SET money='$new_owner' WHERE username='$fetch_bf->owner'"); mysql_query("UPDATE bf SET stock='$nstock', profit='$costs' WHERE location='$fetch->location'"); echo "Bullets Successfully Bought."; $time= time() + 1800; mysql_query("UPDATE users SET last_bullet='$time' WHERE username='$username'"); } }} } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164617 Share on other sites More sharing options...
hyster Posted January 24, 2011 Share Posted January 24, 2011 300 is secs. change to what u want. page.php is the page u want to goto <?php header( 'refresh: 300; url=page.php' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164638 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Does that go in the Bulletfactory page? Or? Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164644 Share on other sites More sharing options...
hyster Posted January 24, 2011 Share Posted January 24, 2011 it goes into the page u want refreshing Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164646 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Warning: Cannot modify header information - headers already sent by (output started at /home/stayway1/public_html/www.one-mafia.com/eng/includes/functions.php:5) in /home/stayway1/public_html/www.one-mafia.com/eng/bf3.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164651 Share on other sites More sharing options...
hyster Posted January 24, 2011 Share Posted January 24, 2011 whats inside functions.php and whats line 6 of bf3.php Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164657 Share on other sites More sharing options...
codefossa Posted January 24, 2011 Share Posted January 24, 2011 If you want it to refresh every 5 mins or so, just use setTimeout Javascript function and window.reload(true) Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164666 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Line 6 of BF.php is the code you posted. Functions is just the basic functions of the website, Doesn't have header anywhere inside it though? Start of functions file: <?php session_start(); include_once "db_connect.php"; $username=$_SESSION['username']; echo "<link rel=stylesheet href=includes/in.css type=text/css>"; ?> <link rel=stylesheet href=includes/in.css type=text/css> <link rel=stylesheet href=in.css type=text/css> <? $query=mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1"); $info = mysql_fetch_object($query); $don=mysql_num_rows(mysql_query("SELECT * FROM donaters WHERE username='$username'")); $langs=mysql_fetch_object(mysql_query("SELECT * FROM user_info WHERE username='$username'")); Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164680 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 If you want it to refresh every 5 mins or so, just use setTimeout Javascript function and window.reload(true) Refreshing just doesn't seem to work though. It seems asif someone HAS to visit the page or something. Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164683 Share on other sites More sharing options...
XistenceNL Posted January 24, 2011 Share Posted January 24, 2011 Ajax may be the way to go? I've got a nice script lying around in here Let me know if intrested. It's a lot of code, in basic you update the div with the time you'll give it. I use it all the time @ work with our own message system Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164686 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Ajax may be the way to go? I've got a nice script lying around in here Let me know if intrested. It's a lot of code, in basic you update the div with the time you'll give it. I use it all the time @ work with our own message system Don't really understand that? Sorry. I'm just lost as to why it only updates when someone views the page. Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164695 Share on other sites More sharing options...
Anti-Moronic Posted January 24, 2011 Share Posted January 24, 2011 Oh, I think I know what you mean. You want php to produce these bullets every 30 minutes, but not depend on a user to view a page? If so, you need to look into cron jobs. Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164697 Share on other sites More sharing options...
codefossa Posted January 24, 2011 Share Posted January 24, 2011 Oh, I think I know what you mean. You want php to produce these bullets every 30 minutes, but not depend on a user to view a page? If so, you need to look into cron jobs. oOo I get what he's goin' for now. You've just clarified his whole problem in my mind. Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164698 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Oh, I think I know what you mean. You want php to produce these bullets every 30 minutes, but not depend on a user to view a page? If so, you need to look into cron jobs. oOo I get what he's goin' for now. You've just clarified his whole problem in my mind. Yess! haha! That's what i want!! Unfortunately i am as new as this post to cronjobs. Best get revising!! Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164703 Share on other sites More sharing options...
codefossa Posted January 24, 2011 Share Posted January 24, 2011 Oh, I think I know what you mean. You want php to produce these bullets every 30 minutes, but not depend on a user to view a page? If so, you need to look into cron jobs. oOo I get what he's goin' for now. You've just clarified his whole problem in my mind. Yess! haha! That's what i want!! Unfortunately i am as new as this post to cronjobs. Best get revising!! I thought you were sayin' it wasn't loading when you refreshed, but it did when you revisited the page .. and I got lost. Well, enjoy learning then and best of luck to ya. Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164707 Share on other sites More sharing options...
XistenceNL Posted January 24, 2011 Share Posted January 24, 2011 1) Upload both .js form the attachment to you're server 2) Ad these lines in you're header <script src="jquery.js"></script> <script src="updatediv.js"></script> Add this to the header: <script> $(document).ready(function() { $("#example ajax").load("file witch you want to reload without revisiting.php"); var refreshId = setInterval(function() { $("#example ajax").load("file witch you want to reload without revisiting.php?randval=\'+ Math.random()); }, 1000); }); </script> That should do the trick, the page get the data without reloading the page. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164711 Share on other sites More sharing options...
Bradley99 Posted January 24, 2011 Author Share Posted January 24, 2011 Will have a go at that mate cheers, Where do i put the code? Which header of which script file? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164714 Share on other sites More sharing options...
XistenceNL Posted January 24, 2011 Share Posted January 24, 2011 Let's say we have an index.php and a data.php. In data.php you'll retreive all the data. In index.php put the code in the header along with the javascripts. make in the index.php a div ajax, define the size as you see fit, then the javascripts will keep that div updated with the interval time you specify. Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1164719 Share on other sites More sharing options...
XistenceNL Posted January 25, 2011 Share Posted January 25, 2011 did it work Quote Link to comment https://forums.phpfreaks.com/topic/225544-php-refresh/#findComment-1165047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.