A better way than sessions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

A better way than sessions?

Post by jeeep »

After having binged on sessions I've noticed that (for example) the files have to be opened to create the cookies inwhich it will recieve. I'm in the process of making a stats page and I'm using imagecreatefrompng, so if file1.php is viewed without opening file2.php nothing will be seen in file1.php. Sessions works with this but it seems kind of pointless. Is there a way to retrieve a variable from another folder within the server (for example $wins; in public_html/folder1/folder2/score.php from public_html/folder1/something.php) other than sessions?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

it is kind of hard to understand what you mean. maybe the design is messed up. usually things are simple.
could you, please, explain that in other words?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Is this is as simple as using includes?
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

I believe so, I did some research on it and every test I ran on it the included page poped up and not the string that I wanted from it.
This is a section of what I have:

Code: Select all

include '/vwar/war.php?wins=numwon'; 
   $wins = $numwon;
 include 'war.php';
    header("Content-type: image/png");
    $bg = "/home/uaxtrem/public_html/teamspeakimg.png";
    $im = @ImageCreateFromPNG($bg);;
    $black = imagecolorallocate($im, 255, 255, 255); 
ImageString($im, 3, 148, 50, $wins , $black);
Is there a way to only include the string I need from this file and not the file itself?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Which file? war.php or teamspeakimg.png
(#10850)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

your probably better off making a global include with a bunch of predefined variables and then including that file on any page u would need any of those variables
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Ok that sounds good. I've been trying to make this work but I cant seem to get it right. Here is what I have:

File 1; modules/vwar/war.php -> where the original variable is ($wins), along with other php code

Code: Select all

if ($ownscoretotal < $oppscoretotal)
			{
				$numlost++;
			}
			else if ($ownscoretotal > $oppscoretotal)
			{
				$numwon++;
$wins=$numwon;
			}
			else if ($ownscoretotal == $oppscoretotal)
			{
				$numdraw++;
			}

			unset($ownscoretotal);
			unset($oppscoretotal);
		}
		$vwardb->free_result($result);
File 2; public_html/varwins.php-> intermediate page to store variable $wins

Code: Select all

<?php
include("/public_html/nuke/modules/vwar/war.php");

global $wins;

?>
File 3; public_html/vwin.php -> Recieves variable from file 2 and displays as a png

Code: Select all

<?php
header("Content-type: image/png");
    $bg = "/public_html/teamspeakimg.png";
    $im = @ImageCreateFromPNG($bg);;
    $black = imagecolorallocate($im, 255, 255, 255);
include '/public_html/varwins.php'; 
  
   
    display_data();
 
function display_data()
{
    ImageString($im, 3, 148, 50, $GLOBALS["wins"], $black);
}
     

Imagepng($im);
ImageDestroy ($im);

?>
What of this looks wrong? Also, is having a file in the modules section going to be a problem since you cant open a file from there server side?
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Also, is display_data(); only for text files?
Post Reply