PHP that displays different button depending on time not working consistently - php

This code was inherited from a previous version of our site http://iowacrisischat.org. It's supposed to show one button if it's between 12pm-2am central time, and another button if it's outside of those hours.
It's working on and off in Chrome, and displaying not only the wrong button but an OLD version of the button in IE and Firefox. I've tried deleting my cookies but it still displays an old version of the button that isn't even in the most recent file uploaded to the site.
So I guess a couple questions. 1) Is the time part of the code what's making Chrome inconsistent? Should it be 0-23 instead of 12 hours, does it need to have minutes? 2) Why would IE and Firefox be showing an old version of the code.
Thank you for any help!!
function crisischat()
{
date_default_timezone_set("America/Chicago");
$hour = date('G', time());
$duringHours = ($hour >= 12 || $hour < 2);
$isProblem = FALSE;
if ($duringHours) {
echo '<div id="chatbtn">.Chat Now.</div>';
} else if ($isProblem) {
echo 'We are experiencing technical difficulties. Please call our crisis line at 1-855-325-4296.';
} else {
echo '<div id="chatbtn">-Chat Now-';
}
}
crisischat();

Related

Main section appears weirdly on wordpress with elementor

i have been having some issues displaying pages properly on the website i'm working,
since an exemple is worth a thousand explanation go visit that web page and you'll see that the main section appears weirdly https://www.lannuaire.fr/0645325643/ .
I've made it dynamic by using this code and calling this function with a shortcode on the page,
the template that it loads is the whole blue section,
public function affiche_tel_non_trouve ()
{
$tel = get_query_var('tel');
$suffixe = $tel[1] ;
if (isset($suffixe) && $suffixe != '6' && $suffixe != '7') {
echo do_shortcode('[elementor-template id="2021"]');
} else if ($suffixe == '6' || $suffixe == '7') {
echo do_shortcode('[elementor-template id="2266"]');
}
}
I've been searching why I have this problem for too long I now am out of clue, I suspect that it is an optimization problem,
so now i seek help, to know why is that happening.
Thank you for your time
(Sorry for the approximate english)
i've also tried loading only the white section since it is the important part but it won't solve the problem, also this display problem doesn't appear using firefox and it is less visible on opera (i'm using chrome).

The PHP is ran twice

I was trying to run a code that inserts new data in my DB but I've noticed that data was inputted twice each time I was running the code.
I've completely changed the code, It's just a Variable Session that increments each time I reloading the PHP page.
But each time I reload the page the incrementation goes by 2 instead of one 1.
Here is the code (It's really simple):
session_start();
echo "test";
echo strval($_SESSION["testCount"]);
if(isset($_SESSION["testCount"])){
$_SESSION["testCount"] = $_SESSION["testCount"] + 1;
}
else{
echo "TESSESSION";
$_SESSION["testCount"] = 0;
}
NOTE: When I run it into privacy mod is working perfectly.

Code for Loading One of Two HTML Pages into a Third HTML Page According to the Time of Day

I have searched the web for an answer to my question, but with limited success. I am a real newbie when it comes to programming languages. Here's my question: I have one HTML page designed with a "daytime" theme and another with a "nighttime" theme. Then I have a third HTML page where I want to load one of these two WHOLE pages into this third page (not into a div or iframe in the third page), according to the time of day. I want to load the "daytime" theme page during the morning and afternoon hours, and the "nighttime" theme page during the evening/nighttime hours.
I have the following PHP code, but it is not working for me:
<?php
$time = date('G');
if($time >=0 || $time < 6)
{
$page = 'indexnight.html';
}
if($time >=6 || $time < 18)
{
$page = 'indexday.html';
}
if($time >=18 || $time < 24)
{
$page = 'indexnight.html';
}
include ('$page');
?>
Can someone check over this and locate any problems with this coding? Also, I need to know where this code should be placed in my third HTML page and if there is any additional coding that needs to go within the body tags of the page.
Thanks for any help you can give me.
hey you used single Quote include ('$page'); Instead use include ("$page");
Shouldn't you control the themes by CSS (which is designed for appearance) rather than HTML (which is designed for content)? But ignoring that, you should do something like:
if ($time >=6 and $time < 18) { readfile('indexday.html');}
else { readfile('indexnight.html');}
And that should replace pretty much all your code (except for the $time definition).

Implementing trial period for local PHP application

I recently finished my PHP app and i would like to know if there's a possibility to have a kind of trial period. So that when that period is reached an error appears on the screen.
Thanks for your time and answers. I most appreciate them.
You can encrypt your sources using Zend Encoder or Ioncube, or obfuscate them.
But the fact is that everything from above can be patched. So if target user is experienced enough - they could remove your trial period checks.
Yes you can: I did the same when the need arose some time ago. Its simple and you can improve it.
Follow this algorithm;
Get today's date
Set the trial period
Add the trial period to today( as start date) to get the expiry date
Check to see if the above code have been executed before
If not then send startdate and `expierydate` into a table in mysql
Else get the start date and compare with today
If it matches displ
Here is the code.
function timebomb(){
$today = date("d-M-Y",time());
$trialPeriod = 1;
$startDate = date("d-M-Y", time());
$getExpiryDate = strtotime('+'.$trialPeriod."days", strtotime($startDate));
$expiryDate = date("d-M-Y", $getExpiryDate);
$checkStatus = mysql_num_rows(mysql_query("SELECT * FROM timebomb"));
if($checkStatus == 0){
mysql_query("INSERT INTO timebomb(StartDate,ExpiryDate) values
('$startDate','$expiryDate')") or die(mysql_error());
}else{
$getPeriod = mysql_query("SELECT * FROM timebomb");
WHILE($period = mysql_fetch_object($getPeriod)){
$endOfTrial = $period->ExpiryDate;
}
IF($endOfTrial == $today){`enter code here`
echo
<center><font size='5' color='red'>
PLEASE YOUR TRIAL PERIOD IS OVER.
IF YOU ENJOYED USING THIS PRODUCT, <br/>
CONTACT ALBERT (0205173224) FOR THE FULL VERSION.
THANK YOU."
;
exit();
}
}
}
timebomb();
One solution can be the using some compiled (or byte compiled ) form of your application instead of source files. checkout this links.
http://php.net/manual/en/book.bcompiler.php, http://www.phpcompiler.org
Follow below steps for fully secured trial period in php projects...
1. create a table in your database for trial period
ex. trial(id,reg_date,days_of_trial).
2. In your index page or login page whatever it is,add code logic as below
i.get 'reg_date','days_of_trial' from 'trial' table.<br/>
ii.get today's date.<br/>
iii.calculate difference using as $dDiff= date_diff($reg_date,$today); <br/>
iv.now compare difference with 'days_of_trial'.<br/><br/>
ex. <br/>
if($dDiff->days>=$row['days_of_trial'])<br/>
{ <br/>
v.update trial table set days_of_trial=0.<br/><br/>
//redirect to expired page..<br/><br/>
ex.
header("Location:http://localhost/project_dir/expired/index.php");}.
3. in expired/index.php file remove your projects main directories as..<br/><br/>
ex.
<br/>
if(file_exists("../folder1"))<br/>
rmdir("../folder1");
redirect to expired page wherein you can display "Trial expired message"<br/>
ex.
<br/>
header("Location: http://localhost/proj_dir/expired/expired.html");<br/><br/>
4. now replace your original home page code to redirect to expired page..
ex.
$file = fopen("../index.php","w");<br/>
fwrite($file,"<?php header('Location: http://localhost/proj_dir/expired/');?>");<br/>
fclose($file);<br/>
Don't forget to take backups of project directory and database..
Your php project is fully secured as in trial period .....

Display content based on date with PHP

I'm putting together a contest site built on Wordpress. Legally, the contest has to start at midnight. To avoid being up at midnight to set up the content, i'd like to build some PHP logic to show everything after the start date, and before then display some basic HTML for a splash page. I'm a TOTAL programming newb, but i'm trying to work the problem out, here's what I have so far:
<?php
// The current date
$date = date('Y, j, m');
// Static contest start date
$contestStart = ('2012, 02, 03');
// If current date is after contest start
if ($date > $contestStart) {
//contest content?
}
else {
// splash content?
}
?>
I feel like there is smarter ways to do this. My site is fairly large... wrapping the whole thing in an if statement seems ridiculous. Maybe a redirect to a different page altogether based on the date?
Any help is appreciated.
You will want to modify your WordPress theme so that the changes can be site-wide.
Log in to your WordPress installation.
Navigate to Appearance > Editor
In the Templates section, go to header.php
At the very beginning of header.php, insert your code :
<?php
$date = time();
$contestStart = strtotime('2012-02-03 00:00:00');
if ($date < $contestStart) {
?>
<html>
Insert your whole splash page here.
</html>
<?php
exit;
}
?>
//The normal template code should be below here.
Don't forget to click the "Update File" button on WordPress when you're done; and like the others said, make sure that your specified time is synced with whatever timezone the server is in.
I suppose technically your code's logic would work but yes, there are much better ways of doing this. However, for your purpose we will go simple.
You should be comparing against a timestamp and not a string. Try this:
<?php
// The current date
$date = time();
// Static contest start date
$contestStart = strtotime('2012-02-03 00:00:00');
// If current date is after contest start
if ($date > $contestStart) {
//contest content?
}
else {
// splash content?
}
?>
You can put the splash and content components in separate .php files, and simply include() then within the conditionals.
if ($date > $contestStart) {
include("SECRETDIR/contest.php");
}
else {
include("SECRETDIR/splash.php");
}
You'll want to set up an .htaccess so that people cannot point their browsers towards secretdir and directly access contest.php
You don't have to wrap the content, you can have something like:
<?php
if ( time() < strtotime('2012-02-03 00:00:00') ) {
echo "not yet!";
exit;
}
//code here wont be executed
Be careful of timezones! Your server might be in a different timezone than your content.
// setup the start date (in a nice legible form) using any
// of the formats found on the following page:
// http://www.php.net/manual/en/datetime.formats.date.php
$contestStart = "February 1, 2012";
// check if current time is before the specified date
if (time() < strftime($contestStart)){
// Display splash screen
}
// date has already passed
else {
// Display page
}

Categories