Current location: Hot Scripts Forums » Programming Languages » PHP » help plsss :(

help plsss :(

Reply
  #1 (permalink)  
Old 07-04-09, 05:06 AM
shemi shemi is offline
Newbie Coder
 
Join Date: Jul 2009
Location: india
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
help plsss :(

hi to all.
i am trying to do form validation through javascript and captcha using php.
when i try to alert for invalid security code, if thecode is correct also, it is giving alert boxes of invalid code and when i click ok button, page is redirecting to the next page.

my form code is
<input type="submit" name="submit" value="submit" onclick="chk();">


chk is a javascript function
PHP Code:
function chk()
  {
  alert("<?php chk1(); ?>");
 
   }
it is calling a function named chk1. it is php function
<?php 
function chk1()
{
 
   if( 
$_SESSION['security_code'] == $_POST['security_code']  )
    {
         
        echo 
'Thank you.code is valid';
        
          
header("Location: process.php"); 
     
   } else {
                 print 
"enter correct security code";

         
   } }  
?>

Last edited by shemi; 07-04-09 at 05:24 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-04-09, 08:22 AM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,543
Thanks: 1
Thanked 22 Times in 22 Posts
The text in the alert function is set when the page is delivered to the browser, it isn't executed when the person clicks submit.

Code:
function chk()
  {
  alert("<?php chk1(); ?>");
 
   }
You could use: reCAPTCHA: Stop Spam, Read Books
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-07-09, 02:33 AM
Zeast Zeast is offline
Newbie Coder
 
Join Date: Apr 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Use Ajax

Search something about ajax on internet and use it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-07-09, 04:21 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,651
Thanks: 0
Thanked 21 Times in 21 Posts
I would not use Javascript for security validation.
You are just asking for trouble.
Javascript can be easily by-passed or over-ridden.
Stick with PHP.
PHP Code:
<?php
session_start
();
$msg "<div>Enter security code: </div>";
if(!empty(
$_POST["sCode"]))
{
 if(
$_SESSION['security_code'] == $_POST["security_code"]){header("location:process.php");}
 else{
$msg "<div style='color:#f00;'>Incorrect security code. Try again.</div>";}
 }
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="#" method="post">
<?php
echo $msg;
?>
<input type="text" name="security_code"><br />
<input type="submit" name="sCode" value="Submit">
</form>
</body>
</html>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-14-09, 04:35 AM
shemi shemi is offline
Newbie Coder
 
Join Date: Jul 2009
Location: india
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
okeey . thanks . i was trying to use with javascript. now i am doing it with php.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:19 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.