1

I've got an url http://www.example.com/?req=welcome.

To get the parameter req I use PHP like this:

      echo $_GET['req'];

This will show the message in the body but this output should vanish after a second.

How do i do that?

Johan
  • 74,508
  • 24
  • 191
  • 319

3 Answers3

6
<div id='req'><? echo $_GET['req']; ?></div>

Then use JavaScript:

window.addEventListener('load', function (){
      setTimeout(function (){
         document.getElementById('req').textContent = '';
      }, 1000); // 1000 is 1s. Set this to how many seconds you want to allow the request to be displayed for.
});
Some Guy
  • 15,854
  • 10
  • 58
  • 67
0

You would use javascript.

You can see an example of that here, using jquery. It's possible to do it without that framework (or any framework). .delay would be replaced by setTimeout() which would enclose your fade out function.

Steve Adams
  • 2,812
  • 22
  • 29
0

You can't - PHP is a server-side language, it has no control over the browser after it finishes sending the output.

Note that you could put your echoed code into a HTML element like a div, and hide it with JavaScript some time after the page loads. Example using jQuery for simplicity:

<div id="hidethisafterawhile"><?php  echo $_GET['req']; ?></div>
<script type="text/javascript">
    $(document).ready(function() {
       window.setTimeout(function(){
         $("#hidethisafterawhile").hide();
       },1000);
    });
</script>
Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
  • @tereško: Did you not understand "example" and "for simplicity"? jQuery is good for showing the relevant parts of the example, as you don't need to worry about `addEventListener` not working in IE6, or the various browser quirks in `textContent`. Nowhere did I say that it's the One True Way of using JS - just that making this example cross-browser without jQuery would detract from its intent. – Piskvor left the building Nov 10 '11 at 08:07