PHP File going to Microsoft Excel “The file is corrupt and cannot be opened” [solved]

Encoutered this issue with a website I was working on. When i convert the data to excel it comes out with message “The file is currpt and cannot be opened”.

When I tried to do research I found a page that says you open the file using notepad and then save it. Once done, you can open it normally.

To my end I was able to solve it by moving the access codes (user , password , database) of the mysql to the actual page itself. Usually I reference it from another php page. But this time, moving it solved my problem

Hope this helps somebody out there

Coffee Cup

Storing Chinese Characters in Mysql / Chinese Characters Not Working in MySQL

Recently transferring to another website, the chinese characters are not working already.

Googling the answer led me to this code, you can convert existing columns one by one, or else you can convert them all at once this way:

mysql> ALTER TABLE nameTable CONVERT TO CHARACTER SET utf8mb4, COLLATE utf8mb4_bin;

mysql> SHOW CREATE TABLE nameTable\G

CREATE TABLE `nameTable` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `version` bigint(20) DEFAULT NULL,
  `country` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL,
  `englishName` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL,
  `chinesename` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin 

After running the code made it ok

Thank you for the web

Coffee Cup

Not Acceptable! An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security [SOLVED]

Working on programming for so many years, it amazes me that i have really much to learn. This recent issue cropped up out of nowhere.

I decided to disable mod security , which is a bad idea honestly. But true enough, i found the culprit. It seems when you pass a get parameter with special characters, our websites seem to be on high alert against hack attack

<IfModule mod_security.c>
  SecFilterEngine Off
  SecFilterScanPOST Off
</IfModule>

What i was passing is the name of a client through get command. Yeah i know . It came out as link.php?name=M&M

I changed then parameter to a session id i had given before and it solved the issue. sigh. another lesson learned.

Coffee Cup

ClipboxTab , SmoothSearch , Dexpredict , FreeCounterStat [FIXED]

Recently one of the websites i was handling started to show strange. When you load the main page, and click with any link or part of the website, it redirects to another page outside of the website.

At first i was puzzled what was causing it. I thought the website has been infultrated or hacked. But it seems everything is still intact.

I separated the main page and tried to dismantle it from there. And you know, what i was the cause, it was a php counter that i got into the website. It seems to be in sleep mode until around 3 years later.

Here are some of the links when you get redirected

https://dexpredict.com/jump/next.php?r=3001031
https://www.smoothsearch.online/install?pubid=2777&productid=30551&clickid=US168345805110000TPHTV422920713914V18
https://clipboxtab.com/install?pubid=2777&productid=30570

Now i know you are dying to know the source. And here it is

https://www.freecounterstat.com

The website gives out a link that you embed in your website

<div id="sfcybjc22f3ctd27lelnzssl4fl8422sw7h"></div>
<script type="text/javascript" src="https://counter10.optistats.ovh/private/counter.js?c=ybjc22f3ctd27lelnzssl4fl8422sw7h&down=async" async></script>
<noscript>
<a href="https://www.freecounterstat.com" title="free hit counter">
<img src="https://counter10.optistats.ovh/private/freecounterstat.php?c=ybjc22f3ctd27lelnzssl4fl8422sw7h" border="0" title="free hit counter" alt="free hit counter">
</a>
</noscript>

The culprit is the first line of the code

<div id="sfcybjc22f3ctd27lelnzssl4fl8422sw7h"></div>

So that’s it. Hope somebody don’t need to learn it the hard way. It’s better you create your own page counter. Either using php & mysql or a txt file to store the current value.

Coffee Cup

#1005 – Can’t create table ‘xxxxxx’ (errno: 150) [SOLVED]

If you are using xampp and you encounter this message during creation of a table, i have found that a lot of them pertain to the unit used to reference the field. If the master table used INT (11), when you reference it as a foreign key, you also need to use the same unit INT(11) as well.

In my case it was different. You see, i got this message because the table I used as a foreign key is the table ‘item’ whereas originally it was table ‘item_list’.

So just in case you encounter this one and still have problems, it might be the table name.

Learn and move forward

Coffee Cup

PHP Reload Page After 10 Seconds

Here is my take on the question, how to refresh the page after 10 seconds

Enjoy

Coffee Cup

<script type="text/javascript">

  var timeout = setTimeout("location.reload(true);",10000);
  function resetTimeout() {
    clearTimeout(timeout);
    timeout = setTimeout("location.reload(true);",10000);
  }
  
</script>  

PHP Code for FB Plugin

Here is the code I used in integrating the fb plugin using iframe into the website.

Please replace the fields that require your actual account.

I also included an html tag .

Enjoy,

Coffee Cup

https://developers.facebook.com/docs/plugins/like-button


JavaScript SDK


Step 1: Include the JavaScript SDK on your page once, ideally right after the opening body tag.
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v14.0" nonce="F1YcA0n6"></script>
Step 2: Place this code wherever you want the plugin to appear on your page.
<div class="fb-like" data-href="https://www.facebook.com/PoshMotorcycleShop" data-width="200" data-layout="standard" data-action="like" data-size="small" data-share="true"></div>


IFrame

<iframe src="https://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2FPoshMotorcycleShop&width=200&layout=standard&action=like&size=small&share=true&height=35&appId" width="200" height="35" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"></iframe>




For Android the URL schema is:

fb://page/page_id
For iOS the URL schema is:

fb://page?id=page_id






https://developers.facebook.com/docs/plugins/like-button

<html>
<head>
  <title>Your Website Title</title>
    <!-- You can use open graph tags to customize link previews.
    Learn more: https://developers.facebook.com/docs/sharing/webmasters -->
  <meta property="og:url"           content="https://www.your-domain.com/your-page.html" />
  <meta property="og:type"          content="website" />
  <meta property="og:title"         content="Your Website Title" />
  <meta property="og:description"   content="Your description" />
  <meta property="og:image"         content="https://www.your-domain.com/path/image.jpg" />
</head>
<body>

  <!-- Load Facebook SDK for JavaScript -->
  <div id="fb-root"></div>
  <script async defer crossorigin="anonymous" 
        src="https://connect.facebook.net/en_US/sdk.js#xfbml=1
             &version={graph-api-version}
             &appId={your-facebook-app-id}
             &autoLogAppEvents=1" 
        nonce="FOKrbAYI">
  </script>

  <!-- Your like button code -->
  <div class="fb-like" 
       data-href="https://www.your-domain.com/your-page.html" 
       data-width=""
       data-layout="standard" 
       data-action="like" 
       data-size="small"  
       data-share="true">
  </div>

</body>
</html>

PHP Date Format

A common mistake that i always do is to forget the strtotime field

Here is where i usually use it.

Enjoy

Coffee Cup


***************************************************

	//20221117
	if ($pldate != '')
	{
		$pldate = date("m/d/Y", strtotime($pldate));
	}
	
	if ($plcheck_date != '')
	{
		$plcheck_date = date("m/d/Y", strtotime($plcheck_date));	
	}
				
?>	
        <div id="page-wrapper">

***************************************************

$pltype = $_POST['pltype'];
$pltype = htmlspecialchars( $pltype, ENT_QUOTES);

	//20160904
	if ($pldate != '')
	{
		$pldate = date("Y-m-d", strtotime($pldate));
	}
	
	if ($plcheck_date != '')
	{
		$plcheck_date = date("Y-m-d", strtotime($plcheck_date));	
		$plcheck_date2 = date("Y-m-d", strtotime($plcheck_date));	
	}
	else
	{
		$plcheck_date2 = NULL;	
	}

***************************************************


Bootstrap Website showing Date Picker using PHP

Configurable-Date-Picker-Plugin-For-Bootstrap

Using angular, a few of the requests were to make the date into a date picker. I have found the code and wanted to share it here

Enjoy,

Coffee Cup

<script   src="https://code.jquery.com/jquery-2.2.3.min.js"   integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="   crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/css/bootstrap-datepicker3.min.css">

<script>
$( document ).ready(function() {
    $("#from-datepicker").datepicker({ 
        format: 'yyyy-mm-dd'
    });
    $("#from-datepicker").on("change", function () {
        var fromdate = $(this).val();
        alert(fromdate);
    });
}); 
</script>

	<div class="form-group">
		<label>Date</label>
		<input type="text" id="from-datepicker"/>
	</div>