nadeemshafi9 Posted December 29, 2007 Share Posted December 29, 2007 hello guys here is the code that i call with an XMLHttpRequest object in javascript every 3 seconds rando(); function rando(){ $d = rand(1, 10); print $d; $d = rand(1, 10); return; } IN PHP 5 everything works fine the number is different every call IN PHP 4 the number stays the same every call i tried destroy session delete unlink and all that no luck HELP PLZ i beg theee Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/ Share on other sites More sharing options...
cooldude832 Posted December 29, 2007 Share Posted December 29, 2007 your function doesn't make sense and it might be erroring without your knolwedge this is what it does ask yourself if this is what you need Makes a random number 1-10 Echoes it and then makes another one and the function is over the second making has no purpose because the local function variables is unset on the end of the function so make your page say this insated <?php echo rand(1,10); ?> that is it no need to do all the extra cause its pointless Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/#findComment-425538 Share on other sites More sharing options...
nadeemshafi9 Posted December 29, 2007 Author Share Posted December 29, 2007 this function is just somthing i done in one second so u guys cant see my work, the thing is in php4 when ajax calls the script it generates a random number reguardless of the script iv shown u , the random number is added to page the ajax is in, this works fine in php 5 but in php 4 for some reason it dosent run the script properly and get the random number new one until i close the browser and open it again. Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/#findComment-425543 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 did u try what I gave you that function you built was broken and if it errors there is your problem Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/#findComment-425602 Share on other sites More sharing options...
nadeemshafi9 Posted December 30, 2007 Author Share Posted December 30, 2007 i tried what u gave me it works fine in php 5 on iis, but in php4 on apache on the server i use it dosent seem to return a different number when called using XMLHttpRequest object from another page, the ajax calls getrand.php whcih outputs teh rand and then the javascript inserts it into teh current page i have a 3 second timout on the javascript function which calls the php script over and over u see this is what shoudl happen like in php 5 on my machine 1 then the ajax happens then 1233213, then teh ajax happens then 2345535 or somthing but on my live server this is whats happening 1 then wait 1 then i wait 1 etc if i close teh browser then it gens a new number this is what happens 3444 and then 3444 and then 3444 its like its not even runing the script more than once could this be ebcause its cachig teh output of teh php script ? Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/#findComment-425614 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 if u just run that page does it return correctly? if so then its not a php problem its your ajax Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/#findComment-425621 Share on other sites More sharing options...
nadeemshafi9 Posted December 30, 2007 Author Share Posted December 30, 2007 thanks v much for ur heal i solved it though i just needed this i know it was prety hard prob, it was very dificult to pinpoint the problem let alon the solution header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" ); header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache"); STOPS AJAX FROMb EING CACHED Quote Link to comment https://forums.phpfreaks.com/topic/83655-solved-rand-and-ajax-php-4-prob-5-ok/#findComment-425650 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.