...

View Full Version : Session Problems



Ryltar
06-14-2005, 10:16 PM
I have a site I am working on that is temp hosted at www.ryltarshadowspell.net and I have a problem with it...

When I visit my site the first time I open a window it works fine... then if I leave to a different site and come back later it takes forever to load...

I have found that this is due to my use of sessions for user log in and out and such... What could I do to stop this problem and still have something that works like sessions?



<?php

session_start( );

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">
<head>

<?php

$pageTitle = "Aerospace and Engineering: Index Page";
echo "<title>" . $pageTitle . "</title>";

?>

<meta name = "Description" content = "Olathe Northwest's Aerospace and Engineering Website" />
<meta http-equiv = "imagetoolbar" content = "no" />
<meta http-equiv = 'content-type' content = 'text/html; charset=utf-8' />

<script type = "text/javascript" src = "/scripts/main.js"></script>

</head>

<body onload = "window.defaultStatus = 'Olathe Northwest Aerospace and Engineering';" >

<table id = "main">

<?php

if ( $_SESSION[ 'loggedIn' ] != false ) {

echo "
<tr class = 'blackBar'>
<td>
<!-- Black Sperator -->
</td>
</tr>

<tr>

<td>

<table id = 'loggedInUser'>

<tr>

<td id = 'leftUser'>

<form action = '/login.php' method = 'post' style='margin-bottom:0;'>

<button type = 'submit' name = 'logOut' value = 'True'>Log Out</button>

</form>

</td>

<td id = 'middleUser'>

<a href = '/login.php'>Welcome " . $_SESSION[ 'name' ] . " to RavenEngineering.net</a>

</td>

<td id = 'rightUser'>

<form action = '/edit.php' method = 'post' style='margin-bottom:0;'>

<button type = 'submit' name = 'newPost' value = 'True'>New Post</button>

</form>

</td>

</tr>

</table>

</td>

</tr>";

}

?>

<tr class = 'blackBar'>
<td>
<!-- Black Sperator -->
</td>
</tr>

<tr id = "BWTitle">

<td>

<a href = '/main.php' onmouseover = "statusIn('Aerospace and Engineering Home'); return true" onmouseout = "statusOut();">Olathe Northwest Aerospace and Engineering</a>

</td>

</tr>

<tr class = 'blackBar'>
<td>
<!-- Black Sperator -->
</td>
</tr>

<tr class = 'whiteBar'>
<td>
<!-- White Sperator -->
</td>
</tr>

<tr id = 'topMenu'>

<td>

<a class = 'topMenuA' href = '/about.php' onmouseover = "statusIn('About'); return true" onmouseout = "statusOut();">About</a>
<a class = 'topMenuA' href = '/images/' onmouseover = "statusIn('Images'); return true" onmouseout = "statusOut();">Images</a>
<a class = 'topMenuA' href = '/staff/staff.php' onmouseover = "statusIn('Staff'); return true" onmouseout = "statusOut();">Staff</a>
<a class = 'topMenuA' href = '/links.php' onmouseover = "statusIn('Links'); return true" onmouseout = "statusOut();">Links</a>

</td>

</tr>

<tr>

<td>

<table id = "leftTable">

<tr>

<td id = "leftTD">

<?php

$leftMenu = array//Array of all the classes for the left menu
(
'/classes.php?pageID=CAD' => array
(
'class' => 'AE CAD',
'description' => 'Computer Aided Design'
),
'/classes.php?pageID=Chemistry' => array
(
'class' => 'AE Chemistry',
'description' => 'Chemical Engineers'
),
'/classes.php?pageID=Math' => array
(
'class' => 'AE Math',
'description' => 'Rockets, Flyers, and Towers'
),
'/classes.php?pageID=Physics' => array
(
'class' => 'AE Physics',
'description' => 'The Mechanics of Things'
),
'/classes.php?pageID=Senior Project' => array
(
'class' => 'AE Senior Project',
'description' => 'BattleBots IQ'
),
);

echo "<div id = 'leftMenu'>\n\n";

foreach ( $leftMenu as $key => $id ) {//displays all the classes

echo "<a class = 'mainMenu' href = '" . $key . "' onmouseover = \"statusIn('" . $id[ 'class' ] . "'); return true\" onmouseout = \"statusOut();\">";
echo "<span class = 'leftMenuHead'>" . $id[ 'class' ] . "</span>";
echo "<br />";
echo "<span class = 'leftMenuSubHead'>" . $id[ 'description' ] . "</span>";
echo "</a>\n";

}

echo "\n</div>\n\n";

?>

</td>

<td id = "rightMenu">

<a href = '/main.php' onmouseover = "statusIn('AE Home'); return true" onmouseout = "statusOut();">

<img src = '/std_images/aelogo.jpeg' width = 570 height = 227 alt = 'ONW Aerospace and Engineering Home Page' />

</a>

</td>

</tr>

</table>

</td>

</tr>

<tr class = 'blackBar'>
<td>
<!-- Black Sperator -->
</td>
</tr>

<tr class = 'whiteBar'>
<td>
<!-- White Sperator -->
</td>
</tr>

<tr class = 'blackBar'>
<td>
<!-- Black Sperator -->
</td>
</tr>

<?php

############################################################################################
### ###
### Configuration ###
### ###

$mysql_hostname = "XXXX"; // Hostname for MySQL
$mysql_username = "XXXX"; // Username for MySQL
$mysql_password = "XXXX"; // Password for MySQL
$mysql_database = "XXXX"; // Default database for MySQL

$admin = "XXXX"; // Name of administrator for error messages
$admin_email = "XXXX"; // Email of administrator

$page_update = date( "F j, Y", mktime( 0, 0, 0, 3, 30, 2005 ) );

//$page_update = date( "F j, Y", time( ) );

### ###
### ###
### ###
############################################################################################

//Connecting, selecting database
$link = mysql_connect( $mysql_hostname, $mysql_username, $mysql_password ) or die( 'Could not connect: ' . mysql_error( ) . " Please contact <a href = 'mailto:" . $admin_email . "'>" . $admin . "</a>." );
mysql_select_db( $mysql_database ) or die( 'Error! Could not select database. Please contact <a href = "mailto:' . $admin_email . '">' . $admin . '</a>.' );

/**********************************************/
/** **/
/** Standard mySQL functions for all pages **/
/** **/
/**********************************************/

function fetchQuery ( $query ) {//Returns mySQL Query

$result = mysql_query( $query ) or die( 'Query failed: ' . mysql_error( ) );

if ( mysql_num_rows( $result ) <= 0 ) {

echo "<h2 align = 'center'>Error! Invalid Database ID, please contact the website administrator!</h2>\n";

} else {

return $result;

}

return $result;

}

function newsQueryDisplay ( $pageID, $length = 140 ) {//News query when passed and id

echo "<table class = 'newsDisplayTable'>\n";

echo " <tr>\n";

echo " <td class = 'newsDisplayTD'>\n";

$result = mysql_query( 'SELECT * FROM announcements WHERE class = "' . $pageID . '" AND date >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH) ORDER BY date DESC' );

if ( @mysql_num_rows( $result ) <= 0 ) {

$result = mysql_query( 'SELECT * FROM announcements WHERE class = "' . $pageID . '" ORDER BY date DESC' );

}

if ( @mysql_num_rows( $result ) <= 0 ) {

echo "<h3 align = 'center'>Error! Invalid Database ID, please contact the website administrator!</h3>\n";

} else {

displayNews ( $result, $length );

}

echo " </td>\n";

echo " </tr>\n";

echo "</table>";

}

function displayNews ( $result, $length = 140 ) {//Takes the query and displays it on the screen

//Print results in HTML
while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {

$title = replaceContent ( $line[ 'title' ] );
$displayContent = replaceContent ( nl2br( $line[ 'content' ] ) );

echo "\n <!-- " . $line[ 'title' ] . " Start -->\n";

echo " <div class = 'announcementDiv'>\n\n";

echo " <div class = 'announcementTitle'>\n";
echo " <span class = 'title'>\n";

if ( $_SESSION[ 'loggedIn' ] != false ) {

echo " <a href = '/edit.php?id=" . textToBinaryConverter( $line[ 'ID' ] ) . "'>" . $title . "</a>\n";

} else {

echo " " . $title . "\n";

}

echo " </span>\n\n";

echo " <span class = 'break'>\n";
echo " <br />\n";
echo " </span>\n\n";

echo " <span class = 'date'>\n";
echo " (posted " . replaceAnnouncement ( $line[ 'date' ] ) . ")\n";
echo " </span>\n\n";

echo " </div>\n";

if ( strlen( $line[ 'content' ] ) >= $length ) {

echo " <div class = 'announcementDetail'>\n";
echo " " . substr( $displayContent, 0, $length ) . "...\n";
echo " <a class = 'readmore' onclick = \"javascript:popup( '/scripts/viewannouncement.php?title=" . urlencode ( $title ) . "&amp;date=" . $line[ 'date' ] . "&amp;content=" . urlencode ( $displayContent ) . "' );\">More</a> \n";
echo " </div>\n";

} else {

echo " <div class = 'announcementDetail'>\n";
echo " " . $displayContent . "\n";
echo " </div>\n";

}

echo " </div>\n";


echo " <!-- " . $line[ 'title' ] . " End -->\n";

}

}

function textToBinaryConverter( $text ) {


$text_array = explode( "\r\n", chunk_split( $text, 1 ) );


for ( $n = 0; $n < count( $text_array ) - 1; $n++ ) {

$binary .= substr( "0000".base_convert( ord( $text_array[ $n ] ), 10, 2 ), -8 );

}


return $binary;

}

function binaryToTextConverter( $binary ) {



$binary_array = explode( "\r\n", chunk_split( $binary, 8 ) );


for ( $n = 0; $n < count( $binary_array ) - 1; $n++ ) {

$string = $string . stripslashes( chr( base_convert( $binary_array[ $n ], 2, 10 ) ) );

}


return $string;

}

function replaceAnnouncement ( $change ) {//Changes the dates to a different format

$year = preg_replace ( "/([0-9][0-9][0-9][0-9])-[0-9][0-9]-[0-9][0-9]/i", "$1", $change );

$change = preg_replace ( "/[0-9][0-9][0-9][0-9]-/i", "-", $change );

//Change to Months
$pattern = array( '/-01-/i', '/-02-/i', '/-03-/i', '/-04-/i', '/-05-/i', '/-06-/i', '/-07-/i', '/-08-/i', '/-09-/i', '/-10-/i', '/-11-/i', '/-12-/i' );
$replace = array( 'January ', 'February ', 'March ', 'April ', 'May ', 'June ', 'July ', 'August ', 'September ', 'October ', 'November ', 'December ' );
$change = preg_replace ( $pattern, $replace, $change );

return $change . ", " . $year;

}

function replaceContent ( $change ) {//Removes all ' and " and such

$pattern = array( "/'/", "/’/", '/"/', '/\\\\"/', '/\\\\&quot;/' );
$replace = array( '&acute;', '&acute;', '&quot;', '&quot;', '&quot;' );
$change = preg_replace ( $pattern, $replace, $change );

return $change;

}

function replaceEvent ( $change ) {//Another date replacer

$change = preg_replace ( "/[0-9][0-9][0-9][0-9]-/i", "-", $change );

//Change to Months
$pattern = array( '/-01-/i', '/-02-/i', '/-03-/i', '/-04-/i', '/-05-/i', '/-06-/i', '/-07-/i', '/-08-/i', '/-09-/i', '/-10-/i', '/-11-/i', '/-12-/i' );
$replace = array( 'January ', 'February ', 'March ', 'April ', 'May ', 'June ', 'July ', 'August ', 'September ', 'October ', 'November ', 'December ' );
$change = preg_replace ( $pattern, $replace, $change );

return $change;

}

?>

<tr>

<td>

<table id = 'about'>

<tr id = 'classHeader'>

<td>

<a class = 'classHeaderA'>Sophomores</a>

</td>

<td>

<a class = 'classHeaderA'>Juniors</a>

</td>

<td>

<a class = 'classHeaderA'>Seniors</a>

</td>

</tr>

<tr id = 'mainNews'>

<?php

echo " <td class = 'newsGroup'>\n";

//Performing SQL query fore grade 10
$result = fetchQuery ( 'SELECT * FROM announcements WHERE year = 10 ORDER BY date DESC LIMIT 4' );
displayNews ( $result, 140 );

echo "
</td>
<td class = 'newsGroup'>\n";

//Performing SQL query fore grade 11
$result = fetchQuery ( 'SELECT * FROM announcements WHERE year = 11 ORDER BY date DESC LIMIT 4' );
displayNews ( $result, 140 );

echo "
</td>
<td class = 'newsGroup'>\n";

//Performing SQL query fore grade 12
$result = fetchQuery ( 'SELECT * FROM announcements WHERE year = 12 ORDER BY date DESC LIMIT 4' );
displayNews ( $result, 140 );

echo "
</td>\n";

?>

</tr>

</table>

</td>

</tr>

<tr class = 'whiteBar'>
<td>
<!-- White Sperator -->
</td>
</tr>

<tr class = 'blackBar'>
<td>
<!-- Black Sperator -->
</td>
</tr>

<tr class = 'blackBar'>

<td>

<table id = 'footer'>

<tr>

<td id = 'footerContents'>

<strong><?php echo $pageTitle ?></strong>
<br />

Page Editor: <?php echo $admin ?><br />
Page Last Updated: <?php echo $page_update ?><br />

<a href = '/contact.php'>Contact Us</a>

<br />

<?php

echo( "Page executed in " );
$execute = microtime( );
print( number_format( $execute, 4 ) );
echo( " seconds." );

?>

</td>

<!-- <td align = 'right'>

<a href = "http://validator.w3.org/check?uri=referer">

<img src = "http://www.w3.org/Icons/valid-xhtml10" alt = "Valid XHTML 1.0!" height = "31" width = "88" />

</a>

</td>
-->

</tr>

</table>

</td>

</tr>

<?php

//Free memory and then close connection

@mysql_free_result( $result );
@mysql_close( $link );

?>

</table>
</body>
</html>

davehaz
06-14-2005, 10:41 PM
hi, I doubt this is due to sessions, as I understand it, when you leave your site for another, your session is ended. all variables should be gone. Are you using cookies? this might be an answer for you.

Ryltar
06-15-2005, 01:52 AM
Well... I had trouble with cookies... but I commented out the session_start( ); on the pages and it works fine... but I need to have that functionalisty or something similar... should I use cookies? and if so, what is the best resource? PHP.net?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum