Jump to content


Photo

Sessions


  • Please log in to reply
4 replies to this topic

#1 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 02 April 2006 - 04:48 PM

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

<?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>

and this is what i have a my town.php

<?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>';
?> 

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.

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 02 April 2006 - 04:59 PM

Change all occurrences of $_session to $_SESSION.



#3 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 03 April 2006 - 12:45 PM

ahh right ok thank, i thought that would of come up with an error :S

that didnt work, it still does the same thing

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 03 April 2006 - 03:22 PM

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.

:)

#5 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 03 April 2006 - 11:51 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users