Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
http://php.flashwebhost.com/sibichan...set_cookie.php
PHP Code:
<?php
if (isset($_COOKIE['memberName'])) {
echo 'Hi ! '. strtoupper($_COOKIE['memberName']) .', Welcome to Group.<br>(<a href=delete_cookie.php>Click here to delete cookie</a>)';
exit;
}
if (isset($_POST['memberName']) && strlen($_POST['memberName']) > 3) {
setcookie('memberName', $_POST['memberName'], time()+3600);
echo 'Cookie Set. Close the browser. Revisit this page, I will remember your name <br>(<a href=delete_cookie.php>Click here to delete cookie</a>)';
}else {
echo ' Enter your Name <form method="post" action=""> <input type="text" name="memberName"> <button type="submit" name="whatever">Enter Group</button> </form>
';
}
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
there is something wrong with the cookie thing.
i read about it and understood it should be first thing to do in a code.
is there something like that?
if why is it like that? why cant we print or show an image an later set a cookie?
setcookie() function use HTTP header/meta data to set cookie, that need to be sent before any real content. You can set cookie after sending image, in that cause, you have to use JavaScript, PHP can't help you there as it sit behind a web server and HTTP protocol required all mata data need to be before real content.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
http://php.flashwebhost.com/austin/day10.php
Code:<?php if(isset($_COOKIE['name'])) { echo 'Hello '.$_COOKIE['name'].' welcome to my world'; exit; } if (isset($_POST['name'])) { setcookie('name',$_POST['name'],time()+(60*3)); echo 'your cookie is set'; } else { echo 'Whats your name? <form method="POST" action=""> <input type="text" name="name"> <button type="submit">GO</button> </form> '; }
http://php.flashwebhost.com/mini/cookie.php
Code:<?php if (isset($_COOKIE['Yoga_name'])) { echo $_COOKIE['Yoga_name'] . ', Welcome to Free Online Yoga Videos'; exit; } if (isset($_POST['Yoga_name']) && strlen($_POST['Yoga_name']) > 3) { setcookie('Yoga_name',$_POST['Yoga_name'], time() + 7200); echo 'Cookie Set. Close the browser. Revisit this page, I will remember your name'; } else { echo ' What is your name ? <form method="post" action=""> <input type="text" name="Yoga_name"> <button type="submit" name="submit">Enter Web Site</button> </form> '; }
Can somebody explain this portion of the script ?
Why phpExpertName and $_POST['phpExpertName'] mentioned together ?Code:setcookie('phpExpertName', $_POST['phpExpertName'], time()+3600);
I do understand that it is the syntax of cookie. Hope I am right.
http://php.flashwebhost.com/vineesh/...set_cookie.php
PHP Code:
<?
if(isset($_COOKIE['userName'])) {
echo '<h2 style="color:red">Hi ' . $_COOKIE[userName] . '!, welcome back.</h2>';
exit;
}
if(isset($_POST['userName']) && strlen($_POST['userName']) > 3) {
setcookie('userName', $_POST['userName'], time() + 3600);
echo '<h3 style="color:red">You may close the browser and re-login, I will remember your Name. </h3>';
} else {
echo '
<html>
<body style="background-color:#D9D9D9">
<form method="POST" action="">
<input type="text" name="userName">
<button type="submit">Click here</button>
</body>
</html>
';
}
Set Cookie: http://php.flashwebhost.com/vineesh/...set_cookie.php
Delete cookie: http://php.flashwebhost.com/vineesh/...del_cookie.phpPHP Code:
<?php
if (isset($_COOKIE['usersName'])) {
echo '<h2 style="color:#EF1725"> You are Mr.' . $_COOKIE['usersName'] . '. I told you na... </h2>';
echo 'To delete cookie, <a href="day_10_ex_7_del_cookie.php">click here</a>';
exit;
}
if (isset($_POST['usersName']) && strlen($_POST['usersName']) > 2) {
setcookie('usersName', $_POST['usersName'], time()+43200); //To remember for 12 hours
echo '<h3 style="color: #5EAE0E">I can remember you for 12 hours!. If you have doubt, refresh the window please...</h3>';
echo '<br>';
} else {
echo '
<html>
<body style="background-color:000589">
<table width="40%" align="center">
<tr>
<td>
<form method="POST" action="">
<h3 style="color: #FFFFFF">Enter your name: </h3>
<input type="text" name="usersName">
<button type="submit">Submit</button>
</form>
</td>
</tr>
</table>
</body>
</html>
';
}
PHP Code:
<?php
setcookie('usersName', "", 0);
echo '<h2>Cookie deleted</h2>';
echo '<br>';
echo 'To go back, <a href="day_10_ex_7_set_cookie.php">click here</a>';
Bookmarks