Jump to content

Archived

This topic is now archived and is closed to further replies.

supanoob

Sessions

Recommended Posts

this is what i have as my login form the one that shows onc you have logged in etc

[code]<?php
session_start();
//this code is compyright to supanoob http://www.twottk.com
// to use this code you must have his permission to gain
// permission please mail him at webmaster@twottk.com
require_once('header.php');

if (!$_POST['user'] || !$_POST['password'])
{
include_once('index.php');
die ('cannot find you in database');
}

$email=$_POST['user'];
$password=$_POST['password'];

$query="select playerid, user, email, fatigue, maxfat, power, speed, dex, intel, health, maxhealth from players where user='$user' and password='$password'";
$result=mysql_query($query);
if (!$result)
{
die (mysql_error());
}

$num_rows=mysql_num_rows($result);
if ($num_rows > 0)
{
$_session['playerid'] = $playerid;
$_session['user'] = $user;
}
?>

<?php
if ($num_rows < 1)
{
die ('Could not find you in the database');
}
?>

<HTML>
<HEAD>
<style type="text/css" media="all">
        @import "css.php";
    </style>
    <TITLE>TWOTTK.COM</TITLE>
</HEAD>
<TABLE width=100% border=0 cellpadding=0 cellspacing=0>
<TR>
    <TD colspan=5>
        <p align="center">
        <img src="http://www.twottk.com/game/banner.jpg" width="730" height="160"></p>
        <TABLE border=0 cellpadding=0 cellspacing=0>
            <TR><TD>
              
              </TD></TR>
        </TABLE>
    </TD>
</TR>
<TR height=20><TD colspan=5 align=left><!-- SPACER --></TD></TR>
<TR>
    <TD align=left width=5><!-- SPACER --></TD>
    <TD align=left WIDTH=20% valign=top>
        <TABLE border=0 cellpadding=0 cellspacing=0 height="85" width="164">
        <TR>
            <TD colspan=2 width=164 height="17"><hr></TD>
        </TR>
        <TR>
        <?php
require_once('cssloggedin.php');
$row=mysql_fetch_array($result);

{
$playerid=($row['playerid']);
$user=($row['user']);
$fatigue=($row['fatigue']);
$maxfat=($row['maxfat']);
$power=($row['power']);
$speed=($row['speed']);
$dex=($row['dex']);
$intel=($row['intel']);
$health=($row['health']);
$maxhealth=($row['maxhealth']);


$_session['playerid'] = $playerid;
$_session['user'] = $user;

?>

                    <TR>
            <TD colspan=2 width=164 height="30">
            Game Stats:<br>
            Health:
            <?php
            echo "$health / $maxhealth"
            ?><br>
            Fatigue:
            <?php
            echo "$fatigue / $maxfat"
            ?><hr>
            <p><hr>Navigation:<br>
            Home<br>
Town
<br>
            Logout<br>
&nbsp;<hr></p>
            <hr></TD>
        </TR>

        <TR height=20>
            <TD height="1" width="164"><!-SPACER-></TD>
        </TR>

        <TR>
            <TD colspan=2 width=164 height="1">
            </TD>
        </TR>
        <TR>
            <TD width=164 bgcolor=#FFFFFF valign=top height="12"><samp>Logged
            In:
            <?php
            echo date ('jS F'); ?><p></samp></TD>
            <TD width=1 bgcolor=#FFFFFF height="12"></TD>
        </TR>
        <TR>
            <TD colspan=2 width=164 height="12">
<hr>            </TD>
        </TR>
        </TABLE>

        <BR>

    </TD>

    <TD align=left width=1%><!-- SPACER --></TD>

    <TD align=left WIDTH=78% valign=top>
    <TABLE width=744 border=0 cellpadding=0 cellspacing=0 height="12">
            <TR>
                <TD valign=top align=left width=4 height="12"></TD>
                <TD valign=top align=center background=templates/default/images/menuback.gif width="736" height="12"><hr></TD>
                <TD valign=top align=right width=4 height="12"></TD>
            </TR>
        </TABLE><TABLE width=740 border=0 cellpadding=0 cellspacing=0>
            <TR>
                <TD width=1 bgcolor=#FFFFFF></TD>
                <TD bgcolor=#FFFFFF width="733" >
                <p align="center">
                <img src="http://www.twottk.com/game/character.jpg" width="105" height="200"></p>
                <div id="gamestats">
           <?php
echo "<b>Character Stats:</b><br /><br />Power: $power <br /> Speed: $speed <br /> Dexterity: $dex <br /> Inteligence: $intel";
}
?></div>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</TD>
            </TR>
        </TABLE>
        <p>&nbsp;</p>
        <TABLE width=748 border=0 cellpadding=0 cellspacing=0 height="39">
            <TR>
                <TD valign=top align=left width=4 height="39">&nbsp;</TD>
                <TD align=center background=templates/default/images/menu_bottom.gif width="740" height="39"><hr></TD>
                <TD valign=top align=right width=4 height="39">&nbsp;</TD>
            </TR>
        </TABLE>
        <br><CENTER>

        <p></p>

        </CENTER>
    </TD>
    <TD align=left width=10><!-- SPACER --></TD>
</TR>
</TABLE>


</BODY>

</HTML>
[/code]

and this is what i have a my town.php

[code]
<?php
session_start();
require_once('header.php');

if ($_SESSION['playerid']);
{
?>
<HEAD>
    <TITLE>TWOTTK.COM</TITLE>
</HEAD>
<TABLE width=100% border=0 cellpadding=0 cellspacing=0>
<TR>
    <TD colspan=5>
        <p align="center">
        &nbsp;</p>
        <TABLE border=0 cellpadding=0 cellspacing=0>
            <TR><TD>
              
              </TD></TR>
        </TABLE>
    </TD>
</TR>
<TR height=20><TD colspan=5 align=left><!-- SPACER --></TD></TR>
<TR>
    <TD align=left width=5><!-- SPACER --></TD>
    <TD align=left WIDTH=20% valign=top>
        <TABLE border=0 cellpadding=0 cellspacing=0 height="85" width="164">
        <TR>
            <TD colspan=2 width=164 height="17"><hr></TD>
        </TR>
        <TR>
        

                    <TR>
            <TD colspan=2 width=164 height="30">

require_once('cssloggedin.php');
$_session['playerid'] = $playerid;
$_session['user'] = $user;
?>
            &nbsp;<hr>
            <p><hr>&nbsp;<hr></p>
            <hr></TD>
        </TR>

        <TR height=20>
            <TD height="1" width="164"><!-SPACER-></TD>
        </TR>

        <TR>
            <TD colspan=2 width=164 height="1">
            </TD>
        </TR>
        <TR>
            <TD width=164 bgcolor=#FFFFFF valign=top height="12">&nbsp;<p>&nbsp;</TD>
            <TD width=1 bgcolor=#FFFFFF height="12"></TD>
        </TR>
        <TR>
            <TD colspan=2 width=164 height="12">
<hr>            </TD>
        </TR>
        </TABLE>

        <BR>

    </TD>

    <TD align=left width=1%><!-- SPACER --></TD>

    <TD align=left WIDTH=78% valign=top>
    <TABLE width=744 border=0 cellpadding=0 cellspacing=0 height="12">
            <TR>
                <TD valign=top align=left width=4 height="12"></TD>
                <TD valign=top align=center background=templates/default/images/menuback.gif width="736" height="12"><hr></TD>
                <TD valign=top align=right width=4 height="12"></TD>
            </TR>
        </TABLE><TABLE width=740 border=0 cellpadding=0 cellspacing=0>
            <TR>
                <TD width=1 bgcolor=#FFFFFF></TD>
                <TD bgcolor=#FFFFFF width="733" >
                <p>
                This is where the town will be displayed</p>
                <div id="gamestats">
</div>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</TD>
            </TR>
        </TABLE>
        <p>&nbsp;</p>
        <TABLE width=748 border=0 cellpadding=0 cellspacing=0 height="39">
            <TR>
                <TD valign=top align=left width=4 height="39">&nbsp;</TD>
                <TD align=center background=templates/default/images/menu_bottom.gif width="740" height="39"><hr></TD>
                <TD valign=top align=right width=4 height="39">&nbsp;</TD>
            </TR>
        </TABLE>
        <br><CENTER>

        <p></p>

        </CENTER>
    </TD>
    <TD align=left width=10><!-- SPACER --></TD>
</TR>
</TABLE>


</BODY>

</HTML>
<?php
{
echo "you are not logged in"
?>


// You may want to use SID here, like we did in page1.php
echo '<br /><a href="login3.php">page 1</a>';
?>
[/code]

now the problem is when i go to town and click the link back it doesnt work, also you can view the town even when not logged in :( although when i click the back to page one link (testing one) it takes me back to the login page. never back to the character page.

Share this post


Link to post
Share on other sites
ahh right ok thank, i thought that would of come up with an error :S

that didnt work, it still does the same thing

Share this post


Link to post
Share on other sites
Read my session troubleshooting post in the FAQ page pinned at the top of the newbie topic area.

Read some session tutorials check your php.ini settings and try a simple test script (like provided in the FAQ Page).

When reporting back, please be as specific as you can of what's going on, provide a URL to the site, and not just post it's not working.

:)

Share this post


Link to post
Share on other sites
well i mailed you with a link etc hope you can help i been looking over the same bit of code for hours at a time :S

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.