views:

151

answers:

3

I have created a html page in php and upon submission i validates that page using PHP. After validating i want to show an alert msg to show its status like showing any greeting or request for re-enter.

I have dont validation. Now i m using

header( 'Location: http://localhost/assignment/WebForm.htm' ) ;

to redirect user to same page but with a alert msg at page load or something like that. What I need to do ?

A: 

You need to show the alert using Javascript in the other page.

You'll probably want to pass the alert text in the querystring.

SLaks
+3  A: 

When you use header, you can't output anything in the document's body, making any alert()ing impossible.

A often used trick to achieve this is to delegate the alert() ing to the target page:

header( 'Location: http://localhost/assignment/WebForm.htm?alert='.
        urlencode("Hello!")) ;

and then in WebForm.htm:

 <?php if (isset($_GET["alert"])): ?>
 <script type="text/javascript">
 alert("<?php echo htmlentities(urldecode($_GET["alert"])); ?>");
 </script>
 <?php endif; ?>

just remember to htmlentities() the output when outputting the message.

If you are already using sessions, for 100% security and elegant URLs, you could also generate a random key in PHP using rand, store the message in $_SESSION["message_$randomKey"] and pass the key in the GET request. That way, the only thing the user sees in the URL is the key, and not the message.

Pekka
@Pekka Please put some torch on htmlentities also. I m unaware of this
Shantanu Gupta
@Shantanu it's to prevent people from injecting HTML through the GET variable. htmlentities() turns any characters that could "break out" of the alert (e.g. a quote `"`) into their HTML entities (`"`)
Pekka
@Pekka: thx for xplanation, It will be a great help
Shantanu Gupta
A: 

whenever i am trying to open any site a

security alert msg box is displaying

the security certificte is from trusted certifying authority

The security certificate has experied.......

plz suggest me some suggestions

as i have already uninstalled my antivirus

uma