Jump to content
php.lv forumi

jquery un sessija


ziedinjsh

Recommended Posts


<html>

<head>

<script type="text/javascript" src="jquery-1.8.3.min.js"></script>

<script type="text/javascript">

jQuery(function(){

jQuery('#form').submit(function(){

jQuery.ajax({

type: 'POST',

url: jQuery('#form').attr('action'),

data: jQuery('#form').serialize(),

success: function(data){

if(data == 'success'){

jQuery('#user').load(location.href+' #user>*');

}else{

jQuery('#info').html(data);

}

}

});

return false;

});

});

</script>

</head>

<body>

<div id="user">

<div id="info"></div>

<?php

session_start();

if(isset($_SESSION['user'])){

echo $_SESSION['user'];

}else{

echo '

<form method="post" action="session.php" id="form">

<input type="text" name="user" />

<input type="submit" name="do" value="ok" />

</form>

';

}

?>

</div>

</body>

</html>


<?php

 

$user = mysql_real_escape_string($_POST['user']);

 

if(empty($user)){

echo 'psc';

}else{

echo 'success';

session_start();

$_SESSION['user'] = $user;

}

 

 

 

?>

Link to comment
Share on other sites


session_start() raksti pašā dokumenta augšā pirms kāds simbols ir izvadīts.

 

no php.net:

This function sends out several HTTP headers depending on the configuration. See session_cache_limiter() to customize these headers.

 

 

 

Link to comment
Share on other sites

Sāc vien ar to, ka palasi mazliet par ( MVC ) kā tādu.

Otrā lieta, sāc šeit ar to, ka php kodu, kas ir kopā ar HTML liec augšā, vēl bonusā session_start(); liec pašā augšā.

ini_set('display_errors', 'On'); error_reporting(E_ALL);

 

Tas jau tev sāks dot pavedienus uz - kapēc neJiet.

Link to comment
Share on other sites

man jau ir
 

<?php 
ini_set('display_errors', 'On'); 
error_reporting(E_ALL); 
session_start(); 
?>
<html>
<head>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
jQuery(function(){
	jQuery('#form').submit(function(event){
   event.preventDefault();
		jQuery.ajax({
			type: 'post',
			url: jQuery('#form').attr('action'),
			data: jQuery('#form').serialize(),
				success: function(data){
					if(data == 'success'){ 
						jQuery('#user').load(location.href+' #user>*');
					}else{
						jQuery('#info').html(data);
					}					
				}
		});
		return false;
	});
});
</script>
</head>
<body>
<div id="user">
<div id="info"></div>
<?php
if(isset($_SESSION['user'])){
echo $_SESSION['user'].' | <a href="off.php">iziet</a>';
}else{
?>
<form method="post" action="session.php" id="form">
<input type="text" name="user" />
<input type="submit" name="do" value="ok" />
</form>
<?php } ?>
</div>
</body>
</html>

 

bet rezūltāts tāds pats!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...