Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Friends i have a code
PHP
<?php <br mode="hold" /?>session_start();

if( isset($_POST['Submit'])) {
   if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
		// Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
		//echo 'Thank you. Your message said "'.$_POST['message'].'"';
		echo "<script>alert('Thank you. Your message said.....')</script>";
		echo "<script type='text/javascript'>
    alert('".json_encode($_SESSION['security_code'])."');
</script>";
		unset($_SESSION['security_code']);
   } else {
		// Insert your code for showing an error message here
		echo 'Sorry, you have provided an invalid security code';
		echo "<script>alert('Sorry, you have provided an invalid security code')</script>";
   }
} else {
?>
<tr>
                        <td height="50" valign="top"> </td>
                        <td valign="top"><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td>
                      </tr>
<tr>
                        <td height="30" valign="top">Security Code:<span class="required" style="color:#93B928;">*</span></td>
                        <td valign="top"><input id="security_code" name="security_code" type="text" style="width:100px;"/></td>
                      </tr>
                       <tr>
                        <td height="50" valign="top"> </td>
                        <td valign="top"><input class="button" name="Submit" value="Send" type="submit" /></td>
                      </tr>
    	}
?>


i want this session value in my java script code
JavaScript
function form_validation()
{
hh=document.WebToLeadForm;
if(!hh.security_code.value==""){
var a = <?php echo $_SESSION['security_code']; ??>
alert("Please wait to check for match");
return false;
}

i use code but not working can u pls figure it out how to use..

thanks in Advance

Rajesh
Posted
Updated 26-Jun-12 0:19am
v2

hi,

one of the way:you can use hidden variable
assign the session value in hidden variable and use document.getElementById()
to fetch the value form hidden variable.
but this is not a secure way :(
any way you are assigning session variable value in JS user can also read the value from JS variable
 
Share this answer
 
Comments
[no name] 26-Jun-12 8:38am    
But how to do this?
not working..
[no name] 26-Jun-12 8:43am    
At this time no need of securty i just want that happen..
adding with vyas_partik20 here is a simple example:
PHP
$data='some data';
?>

<script>
var data="<?php echo $data??>"; //if there is new line you need to do extra care :D
</script>
 
Share this answer
 
Comments
[no name] 26-Jun-12 8:39am    
Not working bro. i submit whole case above..
check that before answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900