One of the issue I ran in to this week was the default upload size of PHPMyAdmin for Importing SQL in to a database. The .sql file was exported from a DB and all of the queries were none DB specific. Rather than trying to edit a few hundred very long queries to be able to execute from MySql command line it was a lot easier to increase these limits in PHPMyAdmin.

My file in question was a little under 100MB, even after hard compression to .gz I could not get the file to under 30MB. A little muddling around show that it appeared to be limits imposed in the PHP.ini file rather than by PHPMyAdmin, there were 2 variables that needed updating.

 php |  copy code |? 
1
post_max_size = 8M

And

 php |  copy code |? 
1
upload_max_filesize = 10M

By changing these values both to 100M PHPMyAdmin accepted and executed the file with out an issue. You may also need to change the below variables if your file needs extracting by PHPMyAdmin

 php |  copy code |? 
1
memory_limit = 128M

Remember after a change to the php.ini file you will need to restart the process for them to take affect. Also I wouldn’t advise having these settings on a public folder or file. Rather than editing the PHP.ini file you may wish to use htaccess to change these variables without restarting the server.

 php |  copy code |? 
1
php_value  upload_max_filesize  100M
2
3
php_value  post_max_size  100M
4
5
php_value  memory_limit  128M 

 

It’s handy to force users to view your website from only one domain, e.g www.example.com over example.com especially when dealing with sessions which are normally not domain specific. Rather than messing with server & cookie settings to try and get sessions to work across domain it is a lot easier to just force them on to one or the other.

It is also important to maintain the original uri they are requesting, in fact this is very easy to do. Take the below code which forces users to www.example.com over example.com

1
define('VALID_DOMAIN', 'www.example.com');
2
3
if(defined(VALID_DOMAIN) && VALID_DOMAIN !== null && $_SERVER['SERVER_NAME'] != VALID_DOMAIN) {
4
      header('location: http://'.VALID_DOMAIN.$_SERVER['REQUEST_URI']);
5
      exit;
6
}

Simple and effective.

Sometimes its handy to know if a website is up or not from code. E.G In a list of websites you are managing. I put this function together to tell me if the site is online or not.

 php |  copy code |? 
01
function site_exists($url) {
02
 if (!empty($url) && ($con = curl_init($url)) !== false) { //start the connection
03
 //Setup connection operators
04
 curl_setopt($con, CURLOPT_TIMEOUT, 10);
05
 curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
06
 
07
 if (($data = curl_exec($con)) !== false && ($code = curl_getinfo($con, CURLINFO_HTTP_CODE)) !== false) {
08
 return true;
09
 }
10
 
11
 curl_close();
12
 }
13
 
14
 return false;
15
 }

by changing line 8 to the below code you can get the http status code for a more detailed report.

8
return $code;

If you are checking a lot of website you may want to change line 4, the current setting tells cURL to wait 10 seconds before failing. However, normally 2-3 seconds is acceptable. If you are checking hundreds of website you may want to turn off (Not available in PHP safe mode) php maximum execution time with set_time_limit ( int $seconds ) or infact turn this on. 

Tag System Example

Example of the tags system

A very simple way of randomizing a tag page to make it look a little more interesting than normal. If you have a little more time and your tag system supports it you can make it so that the popularity of the tag affects it’s size rather than it being random. So that the tags that are used most often are the largest, but that is a task for a rainy day.

 php |  copy code |? 
01
02
03
$tag_sizes = Array('10','15','20');
04
$tag_weights = Array('normal', 'bold');
05
$tag_colors = Array('000000', '660000', '006600', '000066', '666600', '006666', '660066');
06
07
?>
08
09

10
 
11

© 2014 Altroleet Suffusion theme by Sayontan Sinha