vinsb Posted November 8, 2014 Share Posted November 8, 2014 Hi there, I want to make script which will execute via crontab every Sunday at 0:01h and will stop at 23:59h. My goal is to put(show) some tekst on the site. The problem is how to put this tekst in the site? I mean I know how to configure Cron Jobs but how to include the tekst in index.php for example? crontab will be. 1 0 * * 0 /usr/bin/php Start.php 59 23 * * 0 /usr/bin/php Stop.php 1 Quote Link to comment https://forums.phpfreaks.com/topic/292362-cronjob-and-insert-content-in-site/ Share on other sites More sharing options...
hansford Posted November 8, 2014 Share Posted November 8, 2014 Your script is going to have to write to the index.php file. Easy way is to make a template file with a searchable tag you can do a find and replace on like: {{replace_text}} You open the file, search and replace the tags you want. Will need to set the permissions on that file to make it writeable. Then use functions like: fopen() preg_match() or str_replace() fclose() Quote Link to comment https://forums.phpfreaks.com/topic/292362-cronjob-and-insert-content-in-site/#findComment-1496127 Share on other sites More sharing options...
trq Posted November 8, 2014 Share Posted November 8, 2014 Your script is going to have to write to the index.php file. Easy way is to make a template file with a searchable tag you can do a find and replace on like: {{replace_text}} You open the file, search and replace the tags you want. Will need to set the permissions on that file to make it writeable. Then use functions like: fopen() preg_match() or str_replace() fclose() Why would you edit the index.php file? PHP is a programming language, you can use it to dynamically display data from different data sources. Having cron dynamically alter the PHP "script" is ridiculous. Instead, have your cron job put the data somewhere PHP can easily access it (like a database) and then write some logic into your php script to retrieve this data and display it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/292362-cronjob-and-insert-content-in-site/#findComment-1496130 Share on other sites More sharing options...
hansford Posted November 9, 2014 Share Posted November 9, 2014 Listen to the admin, I reread my comment and it is completely ridiculous. Long night, my apologies. Quote Link to comment https://forums.phpfreaks.com/topic/292362-cronjob-and-insert-content-in-site/#findComment-1496137 Share on other sites More sharing options...
jazzman1 Posted November 9, 2014 Share Posted November 9, 2014 I want to make script which will execute via crontab every Sunday at 0:01h and will stop at 23:59h Then you don't have to use two cron jobs. In my example below my regular user (jazzman) sets up a command to be run by cron every Sunday (day 7) at 00:01 AM. 1 0 * * 7 /usr/bin/php -f Start.php The cron task will be finished at Sunday 23:59. Or you want to run the script every minute? Anyways... you don't need to use cronjob here if I understand correctly your wishes. Just create your start.php file with the following data, then include it to the display php file. start.php <?php // set the default timezone to use. date_default_timezone_set('America/Toronto'); $curr_d = date("l"); function displayMessage($day) { if($day != 'Sunday') { return null; } else { return "Today is Sunday"; } } echo displayMessage($curr_d); display.php include('start.php'); Quote Link to comment https://forums.phpfreaks.com/topic/292362-cronjob-and-insert-content-in-site/#findComment-1496150 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.