在同一页面中触发PHP代码

I have one php file named sample.php, which includes the following code:

$abc = new DOTNET("FirstDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxx", "FirstDotNet.Class1");

echo $abc->Connect();
echo $abc->PrintItem();

echo "<img src=\"image.png\" onclick=\"\" />";

What I want is:

  1. Run first two row codes in the beginning of page load (this is ok as usual)
  2. Don't allow the third line code in the beginning of the page load.
  3. Allow to the third line of code to run when I click the image.

Those actions must be on the same php page, not with form posting or with the help of another php file.

Is this possible? How I can trigger the third row of code after the page is loaded?

PHP can't do this, not in one page. I would look into Javascript to control the visibility of the IMG object.

PHP runs the whole file and returns the results to the browser. It doesn't allow you to stop and interact from the browser.