broj1 356 Humble servant Featured Poster

As far as editors are concerned for serious use most people recommend PHP Eclipse http://www.phpeclipse.com/, but it might be to overwhelming for a beginner. If you have Gnome then gedit is very good to start with, if you use KDE then KWrite is equivalent. Try one of these and plan to start learning Eclipse as you get more proficient in PHP.

broj1 356 Humble servant Featured Poster

It seems to me that you are trying to run the script from the command line instead of displaying it in a browser.

In general with PHP you can make two types of scripts:
- applications which are run from command line (php scriptname.php)
- and scripts which are processed on the web server and the result displayed in a browser

You seem to want to do the later since you have PHP within Html code. In this case you have to set up a web server (Apache, Lamp,...) or get web hosting, put the script in appropriate directory and open it with a web browser pointing to specific address.

Judging from your post you have Linux so install and start Apache, put the script in /var/www/html (or similar) and open it with the browser at http://localhost. There are many tutorials arround on how to install, configure and startApache.

broj1 356 Humble servant Featured Poster

For PHP file to run in the browser you have to have a running web server on the machine. I use Fedora and Apache (and Mysql as a database). So check if you have some sort of web server (i.e. Apache or LAMP) installed and started. You can install a web server using software management utility on Ubuntu.

I use Apapche on Fedora and to browse my local PHP scripts I put them in /var/www/html directory (configurable in Apache) and then they can be viewed in browser through http://localhost address. Hope this late reply helps.

broj1 356 Humble servant Featured Poster

Session can not be initiated since HTTP headers have already been sent. The thing is that session sets a cookie which is sent as a header directive. All headers HAVE TO be sent before and only before any content is sent (this is the requirement of the HTTP protocol not PHP).

The reason for this error is in that your script may be sending some content on line 39 (maybe just one space). Have a look there, remove content content or place the session_start() earlier in the script. If it does not help post the code.

broj1 356 Humble servant Featured Poster

Heredoc syntax is a way to use custom identifier to delimit strings in PHP. Usualy string are delimited with single or double quotes, but with heredoc you declare (name) an identifier. This way you do not have to escape single and double quotes anymore. Te rules for chosing identifier name are same as for other labels in PHP. You put identifier in the beginning (after <<<) to let PHP know that now this is the delimiter for the string and you put at the end to let PHP know where the end of the string is. The line with closing identifier shall not contain any other characters (even no indent) which could be the only drawback since it might spoil the look of your code :-).

I use heredoc when I have alot of single and double quotes in text so I do not have to wory about escaping the ones that normaly should be escaped. A simple example of is when generating HTML code with PHP and the code consists of events that call Javascripts function with parameters. Using single or double quotes you would code like this:

$htmlButton = '<input type="button" onclick="someJsFunction(\'parameter1\',\'parameter2\',\'' . $var_parameter3 . '\')" />';
$htmlButton = "<input type=\"button\" onclick=\"someJsFunction('parameter1','parameter2','$var_parameter3')\" />';

Using heredoc syntax you can code this way (maybe a bit cleaner):

$htmlButton = <<< HTMLCODE
<input type="button" onclick="someJsFunction('parameter1', 'parameter2','$var_parameter3')" />
HTMLCODE;

Note variables within heredoc get parsed as with double quoted strings.

There is also nowdoc syntax which is similar but behaves …