|
Posted by Flaming Corncob on 10/11/94 11:55
In article <you-F6837E.00575914082006@news.west.earthlink.net>,
Flaming Corncob <you@wish.com> wrote:
> In article <1155530116.976117.42690@74g2000cwt.googlegroups.com>,
> "Flamer" <die.spam@hotmail.com> wrote:
>
> > Flaming Corncob wrote:
> >
> > > Below is the code I've come up with. So far it works the way I want it
> > > to, but I am an amateur at this whole thing and would like to know if
> > > there's any potential problems with it. It's coded to work in a single
> > > page, linking to itself instead of linking to other pages. NOTE: It
> > > doesn't currently check the account ID that is entered against a
> > > database. That's easy to do. Right now all it does is accept whatever
> > > the user types in as uses it.
> > >
> > > <html>
> > >
> > > <?
> > > if($key!="1701")
> > > {
> > > header("Location:?key=1701&page=page_1");
> > > }
> > > else
> > > // Start: MAIN BODY
> > > {
> > > session_start();
> > > if(!session_is_registered("account_id"))
> > > {
> > > if($page=="post_id")
> > > {
> > > post_id($key);
> > > }
> > > }
> > > else
> > > {
> > > if($page=="member_logout")
> > > {
> > > member_logout($key);
> > > }
> > > }
> > >
> > > echo "<body>";
> > >
> > > if(!session_is_registered("account_id"))
> > > {
> > > member_login($key);
> > > }
> > > else
> > > {
> > > echo "Hello, ".$_SESSION['account_id']."!";
> > > if($page!="page_1")
> > > {
> > > echo "<br><a href='?key=$key&page=page_1'>Goto Page 1</a>";
> > > }
> > > else if($page!="page_2")
> > > {
> > > echo "<br><a href='?key=$key&page=page_2'>Goto Page 2</a>";
> > > }
> > > echo "<br><a href='?key=$key&page=member_logout'>Log Out</a>";
> > > }
> > >
> > > echo "</body>";
> > > // End: MAIN BODY
> > > }
> > >
> > > function member_login($key)
> > > {
> > > echo "<form action='?key=$key&page=post_id' method='post'>";
> > > echo "Account ID: <input type='text' name='account_id'>";
> > > echo "</form>";
> > > }
> > >
> > > function member_logout($key)
> > > {
> > > session_destroy();
> > > header("Location:?key=0");
> > > }
> > >
> > > function post_id($key)
> > > {
> > > session_register("account_id");
> > > $_SESSION['account_id']=$_POST['account_id'];
> > > header("Location:?key=$key");
> > > }
> > >
> > > echo "</html>";
> > > ?>
> >
> > header("location: needs to be a full url starting with http://, also
> > you probably want to put an @ at the start of the @session_destroy
> > command, not needed, however if a cookie isnt set on their pc (ie they
> > refreshed the logout page) they will get an ugly error.
> >
> > Flamer.
>
> Ok, than is there a way to have it default to a specific page.. for
> example if I were to use BASE to have links default to one page? I tried
> using BASE in this situation but as it's used in the "head" tag it scews
> up a session.
Ok, how's this modification?
<html>
<?
$base_link="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
?>
<?
if($key!="1701")
{
header("Location:$base_link?key=1701&page=page_1");
}
else
// Start: MAIN BODY
{
session_start();
if(!session_is_registered("account_id"))
{
if($page=="post_id")
{
post_id($key, $base_link);
}
}
else
{
if($page=="member_logout")
{
member_logout($key, $base_link);
}
}
echo "<body>";
if(!session_is_registered("account_id"))
{
member_login($key, $base_link);
}
else
{
echo "Hello, ".$_SESSION['account_id']."!";
if($page!="page_1")
{
echo "<br><a href='$base_link?key=$key&page=page_1'>Goto Page 1</a>";
}
else if($page!="page_2")
{
echo "<br><a href='$base_link?key=$key&page=page_2'>Goto Page 2</a>";
}
echo "<br><a href='$base_link?key=$key&page=member_logout'>Log Out</a>";
}
echo "</body>";
// End: MAIN BODY
}
function member_login($key, $base_link)
{
echo "<form action='$base_link?key=1701&page=post_id' method='post'>";
echo "Account ID: <input type='text' name='account_id'>";
echo "</form>";
}
function member_logout($key, $base_link)
{
@session_destroy();
header("Location:$base_link?key=0");
}
function post_id($key, $base_link)
{
session_register("account_id");
$_SESSION['account_id']=$_POST['account_id'];
header("Location:$base_link?key=0");
}
echo "</html>";
?>
Navigation:
[Reply to this message]
|