|
-
May 24th, 2007, 05:42 AM
#1
Thread Starter
Member
show example of session code
i m new in using session.
can anyone show me an example of session code? like for example, when the user has entered their information in the fields and when they click onto the submit button, they will be redirected to the next page-with all their information being displayed.
can anyone show me the example of the code?
-
May 24th, 2007, 04:14 PM
#2
Re: show example of session code
<?
session_start();
session_register("MyVariableName");
$MyVariableName = 8329;
?>
-
May 25th, 2007, 02:01 AM
#3
Re: show example of session code
Mendhak, your code has become obsolete. One should use the $_SESSION array now:
PHP Code:
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['sessionVar'] = $_POST['sessionVar'];
}
?>
<html>
<body>
<?php if (isset($_SESSION['sessionVar'])): ?>
<p>You entered <?php echo(htmlspecialchars($_SESSION['sessionVar'])) ?></p>
<?php else : ?>
<form method="post">
<input type="text" name="sessionVar" />
<input type="Submit" name="submit" />
</form>
<?php endif; ?>
</body>
</html>
-
May 25th, 2007, 02:45 AM
#4
Re: show example of session code
On a slight tangent, when you handle a POST request you should silently redirect to the intended eventual location using a 303 redirection status code. This instructs the user agent not to cache the response and avoid the irritating "This page contains POSTDATA that has expired from cache" message if you try to go back or refresh the page.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|