Welcome to WebmasterWorld Guest from 54.145.101.33

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

session start(); problems?

having a few issues with sessions

     
7:36 pm on Aug 13, 2012 (gmt 0)

New User

joined:Aug 13, 2012
posts:2
votes: 0


Hi guys,

New to PHP and I am trying to add PHP functions for my game server. A ranking and a players online script. I added those functions on a sidebar.php file and I am using the include function on all of my pages. The scripts work on the index page, but it doesn't on all the others and I cannot think as to why.

Heres my code:

sidebar.php:
<aside class="left">
<div class="players"><?php
if( !session_start() )
{
session_start();
}
require "config.php";
include "functions.php";
$langfile = "lang/{$_CONFIG[Language]}.php";
include $langfile;

$connection = connect();
?>
<?php
$query = odbc_exec($connection, "SELECT CurrPlayer FROM ServerStatus(nolock) WHERE Opened != 0");
$count = 0;
while( odbc_fetch_row($query) )
{
$count = $count + odbc_result($query, 1);
}
echo $count;
?></div>
<p><img src="images/donate.png" alt="Donate to help us"></p>
<p><img src="images/dlreg.png" alt="Vote for Us!"></p>
<div class="newstop">Ranking</div>
<?php
//MSSQL Connection
$con = mssql_connect("****\SQLEXPRESS","user","pass");
if (!$con)
{
die('Couldnt not connect: ' . mssql_error());
}

mssql_select_db("GunzDB");
?>

<?php
//Player Ranking- It will display top 10 players if you want lower or higher look 1 line down and change 10 to your number.
$result = mssql_query("SELECT TOP 10* FROM Character ORDER BY Level DESC");

echo "<center><table border='1'>
<tr>
<th>Rank</th>
<th>Character Name</th>
<th>Level</th>
</tr>";

$x = 1;
while($row = mssql_fetch_array($result))
{
echo "<tr>";
echo "<td>#" . $x . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Level'] . "</td>";
echo "</tr>";
$x++;
}

echo "</center></table>";
mssql_close($con);
session_destroy();
?>
</aside>


And index.php (the same code displays on the other pages, but only works on this page):
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta name="description" content="GunZ Unleashed is a GunZ server created for fun.">
<meta name="keywords" content="fun, gunz, server, basic, ijji, MAIET">
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/nav.css">
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>GunZ Unleashed - Here Comes The Pain!</title>
</head>

<body class="no-js">
<script>
var el = document.getElementsByTagName("body")[0];
el.className = "";
</script>
<noscript>
<!--[if IE]>
<link rel="stylesheet" href="css/ie.css">
<![endif]-->
</noscript>
<div id="wrapper">
<div class="center"><a href="index.php"><img src="images/header.png" alt="GunZ Unleashed Home" width="960" height="140" /></a></div>
<nav id="topNav">
<ul>
<li><a href="index.php" class="current">Home</a></li>
<li><a href="about.php">About</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="download.php">Download</a></li>
<li><a href="synopsis.php">Synopsis</a></li>
<li><a href="#" title="Nav Link 1">Donate</a>
<ul>
<li><a href="#" title="Sub Nav Link 1">Forum Donation</a></li>
<li><a href="#" title="Sub Nav Link 2">In-Game Donation</a></li>
<li><a href="#" title="Sub Nav Link 3">Item Shop</a></li>
</ul>
</li>
<li><a href="contact.php">Contact</a></li>
<li><a href="http://forum.gunzunleashed.net">Forums</a></li>
</ul>
</nav>

<div id="content">
<?php include 'sidebar.php'; ?>
<div class="news">
<div class="newstop">Changes to v3 OBT <a class="right" href="#">By Daniel</a></div>
<div class="newsbox">There will be a few changes to the Open BETA Test, first one instead of migrating all accounts over to v3 we will start from scratch
change the exp rate to 65x for 1 week and give everyone a new Artistic Shotgun for 7 days from the day of claiming it. More information regarding the free donator item
will be announced soon.</div>

<p></p>

<div class="newstop">The all-in-one Package <a class="right" href="#">By Daniel</a></div>
<div class="newsbox">We are proud to release our new website alongside our new Version 3 Client.
We felt, that if we were going to release a client, we need to release a new template too. We are still working
on a login system, and an item shop, but right now it is under construction.</div>

<p></p>

<div class="newstop">Upcoming Events <a class="right" href="#">By Jumparound</a></div>
<div class="newsbox">Upon the v3 release we are going to be hosting some events, we haven't got a full list yet
but we will be including a video event, others will not be revealed just yet.</div>
</div>
</div>

<div id="footer">
&copy; Copyright GunZ Unleashed 2008-2012, All Rights Reserved.
<div class="right">Site Designed by <a href="http://surgenetwork.co" target="_blank">Surge Network</a></div>
</div>
</div>
<script src="js/jquery.js"></script>
<script src="js/modernizr.js"></script>
<script>
(function($){

//cache nav
var nav = $("#topNav");

//add indicator and hovers to submenu parents
nav.find("li").each(function() {
if ($(this).find("ul").length > 0) {
$("<span>").text("^").appendTo($(this).children(":first"));

//show subnav on hover
$(this).mouseenter(function() {
$(this).find("ul").stop(true, true).slideDown();
});

//hide submenus on exit
$(this).mouseleave(function() {
$(this).find("ul").stop(true, true).slideUp();
});
}
});
})(jQuery);
</script>
</body>
</html>


I also have some previews, this is what it is supposed to look like:
[i46.tinypic.com...]

And this is what it looks like on other pages:
[i49.tinypic.com...]

If anyone can help I would really appreciate it!

Thanks,
Dan.
7:28 am on Aug 14, 2012 (gmt 0)

New User

joined:Aug 13, 2012
posts:2
votes: 0


Nevermind, managed to figure it out by googling and using session id's. If someone could close this please?
7:25 pm on Aug 17, 2012 (gmt 0)

New User

10+ Year Member

joined:May 17, 2007
posts: 17
votes: 0


Hi...

Simple put

<?php
if( !session_start() )
{
session_start();
}
?>


On "very first line of the page".

That will sort out all your trouble
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members