470,848 Members | 1,189 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

scope over multiple pages

I need to preserve some values over several pages. I want the user to
enter his username, password and the IP address of the MySQL server at
the beginning of a series of pages. I want all the pages to know these
values. I want all the pages to display these values so the user can
change them or not.
The "series" of pages is an HTML page that gathers this information.
This is sent to a PHP server page. The server page may have to re-load
itself if the user chooses to re-sort the data. If I had it the way I
want it, the username, password and IP would be gathered in the HTML
page at the beginning and be available to the server page even when it
re-loads itself. I also want the HTML page (if visited again) to
display the original values in the text boxes.
I have tried $_POST, hidden variables within forms, $GLOBAL (which I
couldn't get to work at all) and probably some other ways to do this.
Needless to say, I couldn't get the results I wanted from any of these.
HELP!

Jul 17 '05 #1
2 1663
Jeff Sandler wrote:
I need to preserve some values over several pages. I want the user to
enter his username, password and the IP address of the MySQL server at
the beginning of a series of pages. I want all the pages to know these
values. I want all the pages to display these values so the user can
change them or not.
The "series" of pages is an HTML page that gathers this information.
This is sent to a PHP server page. The server page may have to re-load
itself if the user chooses to re-sort the data. If I had it the way I
want it, the username, password and IP would be gathered in the HTML
page at the beginning and be available to the server page even when it
re-loads itself. I also want the HTML page (if visited again) to
display the original values in the text boxes.
I have tried $_POST, hidden variables within forms, $GLOBAL (which I
couldn't get to work at all) and probably some other ways to do this.
Needless to say, I couldn't get the results I wanted from any of these.
HELP!


:-))

Use session variables.

<?php // page1.php
session_start();
$name = isset($_SESSION['name']) ? $_SESSION['name'] : '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$_SESSION['name'] = $_POST['name'];
exit('Go to <a href="page2.php">page 2</a>.');
}
echo <<<HTML
<form action="page1.php" method="post">
<input type="text" name="name" value="$name"/>
<input type="submit"/>
</form>
HTML;
?>
<?php // page2.php
session_start();
if (!isset($_SESSION['name'])) {
echo 'You need to enter your name. ';
exit('Please goto <a href="page1.php">page 1</a>.');
}
echo 'Welcome ', $_SESSION['name'];
?>

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
ditto what Pedro said,

here's my version (cut/paste from a previous post).

http://www.php.net/reserved.variables
$_SESSION is particularly cool, but you need to run the session_start()
function first before it works. Unfortunately the above page neglects to
mention that and it has caught some people out.

As a newbie, you will want to make sure you get to know PHP's session
handling capabilities -- IT WILL SAVE YOU A LOT OF WORK!
http://www.php.net/manual/en/ref.session.php
remember that before the $_SESSION superglobal came along, it was
neccesary to use the other session functions all the time, now you can
do things like.

<?php

session_start();

if(!isset($_SESSION["uname"])) {
if(blnAutheticated($_POST)) { // use form data
$_SESSION["uname"] = $_POST["uname'];
}
else {
header("Location: login.php"); // redirect them
die();
}
}
echo "You are currently logged in as ".$_SESSION["uname"];
?>

obviously the above code requires you to write a blnAutheticated()
function which accepts an associative array that it will search for
authentication tokens.

function blnAutheticated($arrPost) {
$blnAuth = false;
$sqlCheck = "SELECT * FROM users WHERE "
."uname = '".$arrPost["uname"]."'";
."uname = '".$arrPost["uname"]."'";
if($arrPost)
}
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Hal Vaughan | last post: by
7 posts views Thread by Anna K. | last post: by
4 posts views Thread by Gery D. Dorazio | last post: by
41 posts views Thread by Miguel Dias Moura | last post: by
9 posts views Thread by Graham | last post: by
7 posts views Thread by Christian Christmann | last post: by
reply views Thread by David Troxell - Encourager Software | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.