473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1737
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hal Vaughan | last post by:
Being self taught, this is one thing I've always had trouble with -- I finally get it straight in one situation and I find I'm not sure about another. I have a class that keeps calling an...
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
7
by: Anna K. | last post by:
Hi Experts, I want to create an object within the session scope (one that will be unique to everyone who logs into the system), yet persist throughout the login session. Would the "document"...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
0
by: David Troxell - Encourager Software | last post by:
Product Scope 7 (http://www.encouragersoftware.com/) and Profile Exchanges enhanced with SetupCast publishing methods NOTE: If you are a software author, releasing commercial and/or shareware...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.