Welcome to WebmasterWorld Guest from

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

5+ Year Member

joined:Aug 13, 2012
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:

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

$connection = connect();
$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;
<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>
//MSSQL Connection
$con = mssql_connect("****\SQLEXPRESS","user","pass");
if (!$con)
die('Couldnt not connect: ' . mssql_error());


//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'>
<th>Character Name</th>

$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>";

echo "</center></table>";

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


<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>
<title>GunZ Unleashed - Here Comes The Pain!</title>

<body class="no-js">
var el = document.getElementsByTagName("body")[0];
el.className = "";
<!--[if IE]>
<link rel="stylesheet" href="css/ie.css">
<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">
<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>
<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>
<li><a href="contact.php">Contact</a></li>
<li><a href="http://forum.gunzunleashed.net">Forums</a></li>

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


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


<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 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>
<script src="js/jquery.js"></script>
<script src="js/modernizr.js"></script>

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

//add indicator and hovers to submenu parents
nav.find("li").each(function() {
if ($(this).find("ul").length > 0) {

//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();

I also have some previews, this is what it is supposed to look like:

And this is what it looks like on other pages:

If anyone can help I would really appreciate it!

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

New User

5+ Year Member

joined:Aug 13, 2012
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


Simple put

if( !session_start() )

On "very first line of the page".

That will sort out all your trouble