variable visibility when using <a href></a>
am 29.05.2002 16:46:15 von Jules Alberts
hello world,
sorry if this is off topic, but the question arose when i was buidling
a test system with PHP4 / postgresql.
i want a user to enter a user ID and password in order to make a non-
permanent database connection. so the application (that consistes of
several PHP and HTML files) should remember the values in variables.
a logical approach seemed to be global variables, however, this doesn't
work when new pages are generated. in this small example:
// this is file main.php
echo "
";
$password="fubar";
echo "password is: \"$password\"
";
echo "";
echo "";
?>
// this is file sub.php
echo "";
global $password; // doesn't work
echo "password is: \"$password\"
";
echo "";
?>
the variable $password is not visible in sub.php. i guess this is
because the href link creates a new page, a fresh start. still i want
$password to be visible in sub.php. what is a good, safe way to do
this? setting serverside environment variables sounds dangerous. and i
would like to avoid cookies (unless it's the only way). i thought about
include_once(), but you can't call that from a link. or can you?
how is this normally done? TIA for any tips!
--
Jules Alberts
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
Re: variable visibility when using <a href></a>
am 29.05.2002 17:08:26 von dbrown
How about using a session?
session_start()
$password="fubar";
session_register("password");
then on the next page (sub.php) call session_start(); again and
$password will become visable.
see http://www.php.net/manual/en/function.session-start.php
Dave
Jules Alberts wrote:
>hello world,
>
>sorry if this is off topic, but the question arose when i was buidling
>a test system with PHP4 / postgresql.
>
>i want a user to enter a user ID and password in order to make a non-
>permanent database connection. so the application (that consistes of
>several PHP and HTML files) should remember the values in variables.
>
>a logical approach seemed to be global variables, however, this doesn't
>work when new pages are generated. in this small example:
>
> // this is file main.php
>
> echo "
";
> $password="fubar";
> echo "password is: \"$password\"
";
> echo "";
> echo "";
> ?>
>
> // this is file sub.php
>
> echo "";
> global $password; // doesn't work
> echo "password is: \"$password\"
";
> echo "";
> ?>
>
>the variable $password is not visible in sub.php. i guess this is
>because the href link creates a new page, a fresh start. still i want
>$password to be visible in sub.php. what is a good, safe way to do
>this? setting serverside environment variables sounds dangerous. and i
>would like to avoid cookies (unless it's the only way). i thought about
>include_once(), but you can't call that from a link. or can you?
>
>how is this normally done? TIA for any tips!
>
>
>
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Re: variable visibility when using <a href></a>
am 30.05.2002 09:30:37 von Jules Alberts
On 29 May 2002 at 10:08, David C. Brown wrote:
> How about using a session?
>
> session_start()
> $password="fubar";
> session_register("password");
>
>
> then on the next page (sub.php) call session_start(); again and
> $password will become visable.
>
> see http://www.php.net/manual/en/function.session-start.php
>
> Dave
thanks Dave, i didn't know the concept of sessions. i had a google on
the subject, i guess using $_SESSION would be the safest approach. i'll
have a good look at it first before using it, the password stored will
give access to a database with privacy-sensitive data, so safety is
very important.
--
Jules Alberts
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly