Jump to content

[SOLVED] rand() and AJAX php 4 prob 5 ok


nadeemshafi9

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.