Thursday, October 9, 2014

PHP web link problem

When you add the below html link to your php file
@ 2014 Designed by Qiunique All rights reserved.

The website doesn''t go to  www.linkedin.com/in/xiaoshu, but a sub-directory instead. The trick is to add http: in front of the link, otherwise php thinks they are special characters and will try to go to its subdirectory and look for it.

@ 2014 Designed by Qiunique All rights reserved.

HTTP Header already sent

This will happen if you include a separate php form on the index.php page, but you have something else (other html code) before this php form. In this case, you need to turn on output buffering.

There are some Lynda.com videos which offer detailed explanation on HTTP header and output buffering:

PHP with MySQL Essential Training - Modifying Headers, page redirection, and output buffering

You can turn on output buffering either on each php file, or you can do it in the php.ini. Only one way is required but you are free to do both. 

Very often, you won't have access to your php.ini files on the server. You can modify all php files by doing the below:

at the beginning of all the php files, write
  ob_start(); 
?> 

at the very end of the php files, write
  ob_end_flush(); 
?> 

Bear in mind that if you do an include (anotherfile.php) in the index.php file, you might need to modify the file directories for the css, js, or whatever other files you have in the included php file, as this file is seeing the folder structure from the root level.