bgeorge82 Posted March 28, 2009 Share Posted March 28, 2009 I'm a newbie here, so please try to bear with me. I have a number of files on my webserver that I want to run every hour, normally I would a cron job, but I need to run some of the files with a variable: e.g 'a.php?num=20' some of these scripts are basically copies of themselves with different user data if that has any bearing. But I tried to use the include function (later figured out it didn't support variables), Any thoughts or idea? I would like to run 1 sleep is for 10 seconds then run the next and so on and so forth. Any help is greatly appreciated thanks! (webserver is php5, apache) Thanks! Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 28, 2009 Share Posted March 28, 2009 include supports variables. You just set the variable before you include the file $variable="BLAH"; include("echovariable.php"); echovariable.php echo $variable; Quote Link to comment Share on other sites More sharing options...
bgeorge82 Posted March 28, 2009 Author Share Posted March 28, 2009 I had this earlier, and basically it comes back: #!/ramdisk/bin/php5 Read the PHP file which I assume is working correctly But I actually want it to execute the php script with the variable as if I were just going to it through the web. For instance I run these manually by typing in the HTTP address: http://example.com/example.php?num=20 and then the same for example1.php example2.php, etc Quote Link to comment Share on other sites More sharing options...
Philip Posted March 28, 2009 Share Posted March 28, 2009 I have a number of files on my webserver that I want to run every hour, normally I would a cron job, but I need to run some of the files with a variable: e.g 'a.php?num=20' some of these scripts are basically copies of themselves with different user data if that has any bearing. You can pass them as arguments in the PHP file. Here's a good example: http://web.jaypedia.com/web/cron/how-to-pass-php-cron-job-parameters-arguments-or-variables.htm Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 28, 2009 Share Posted March 28, 2009 session's or $_GET[''] <?php // url websit/name.php?cmd=redarrow if(isset($_GET['cmd'])){ echo $_GET['cmd']; } ?> . more safe. <?php // url websit/name.php?cmd=redarrow if(isset($_GET['cmd'])&& $_GET['cmd']!=''){ echo $_GET['cmd']; } ?> Quote Link to comment Share on other sites More sharing options...
bgeorge82 Posted March 28, 2009 Author Share Posted March 28, 2009 King Philip --- Thanks if I can't seem to get this I will give that a solid go. Red arrow this is what I went ahead and did, and no errors popped out, but the script didn't seem to run (sorry i'm very new at this) <?php // url http://example.com/abc.php?num=20 if(isset($_GET['num'])&& $_GET['num']!=''){ echo $_GET['num']; } ?> That was my code (url changed) Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 28, 2009 Share Posted March 28, 2009 tested. test it your self mate. <?php echo "<a href='{$_SEVER['PHP_SELF']}?num=20'>Link</a>"; if(isset($_GET['num'])&& $_GET['num']!=''){ echo $_GET['num']; exit; }else{ echo "sorry does not match!"; } ?> look at this for fun. <?php session_start(); $array=array(1,2,3,4,5); $arra=implode(' ',$array); $_SESSION['num']=$array; echo "<a href='{$_SEVER['PHP_SELF']}?num={$_SESSION['num']}>Link</a>"; if(isset($_GET['num'])&& $_GET['num']!=''){ $result=implode(' ',$_SESSION['num']); echo $result; exit; }else{ echo "sorry does not match!"; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 28, 2009 Share Posted March 28, 2009 my second example was crap ignore it ok, look at this one quite interesting i say. <?php session_start(); $array=array(1,2,3,4,5); $implode=implode(' ',$array); $_SESSION['cmd']=$implode; echo "<a href='{$_SEVER['PHP_SELF']}?num=".$_SESSION["cmd"]."'>Link</a>"; if(isset($_GET['num'])&& $_GET['num']!=''){ $result=explode(' ',$_GET['num']); $_SESSION['res']=implode(' ',$result); echo $_SESSION['res']; exit; }else{ echo "sorry does not match!"; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 28, 2009 Share Posted March 28, 2009 hope all these ways help. even better cheek this out. <?php session_start(); $array=array("redarrow","php","myslq","html","css"); $implode=implode(' ',$array); $_SESSION['cmd']=$implode; echo "<a href='{$_SEVER['PHP_SELF']}?num=".base64_encode($_SESSION["cmd"])."'>Link</a>"; if(isset($_GET['num'])&& base64_decode($_GET['num'])!=''){ $result=explode(' ',base64_decode($_GET['num'])); $_SESSION['res']=$result; } if(isset($_SESSION['res'])){ echo"<br>"; echo $_SESSION['res'][0]; echo"<br>"; echo $_SESSION['res'][1]; echo"<br>"; echo $_SESSION['res'][2]; echo"<br>"; echo $_SESSION['res'][3]; echo"<br>"; echo $_SESSION['res'][4]; session_destroy(); } ?> Quote Link to comment 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.