I'm Learning But Stumped... Session Help

A beginner who has learned much the past few weeks but needs a bit of

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 1719 Views - Last Post: 17 December 2008 - 02:39 AM Rate Topic: -----

#31 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2934
  • View blog
  • Posts: 10,139
  • Joined: 08-August 08

Re: I'm Learning But Stumped... Session Help

Posted 16 December 2008 - 08:57 PM

Here's a simple example. Because it's simple, it doesn't really show the advantages well, but if you imagine a larger program where more complicated things are being done, you'll see that they get done within the object, simplifying the overall code.
<?php

class box
	{
	var $height;
	var $width;
	var $depth;
	var $front_area;
	var $side_area;
	var $top_area;
	var $volume;

	function areas()
		{
		$this->front_area = $this->height * $this->width;
		$this->side_area = $this->height * $this->depth;
		$this->top_area = $this->width * $this->depth;
		}
	function volume()
		{
		$this->volume = $this->height * $this->width * $this->depth;
		} 
	}
	
$big_box = new box; 
$big_box->height = 20;
$big_box->width = 30;
$big_box->depth = 50;
$big_box->areas();
$big_box->volume();

$small_box = new box;
$small_box->height = 5;
$small_box->width = 3;
$small_box->depth = 4;
$small_box->areas();
$small_box->volume();

echo "The small box front area is: ".$small_box->front_area." square units and the big box front area is: ".$big_box->front_area." square units.<br>";

?>


This post has been edited by CTphpnwb: 16 December 2008 - 09:00 PM

Was This Post Helpful? 1
  • +
  • -

#32 RayRayAngel  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 15-December 08

Re: I'm Learning But Stumped... Session Help

Posted 16 December 2008 - 09:07 PM

Ahh most excellent! That really makes sense and should help me keep things a bit clearner. It'll be a pain to go back and move stuff around but I think in the end it will be fully worth it.
Was This Post Helpful? 0
  • +
  • -

#33 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: I'm Learning But Stumped... Session Help

Posted 17 December 2008 - 02:39 AM

I personally think, and please feel free to correct me if i am wrong, but you might be better off storing the session_id (whether you use the default or create your own with random numbers) and the client's IP. If a session is accessed from a different IP you can be sure it's a hack. If the session id and ip address match up then you keep them logged in.

Obviously I mean their external IP (the one viewable from the internet) and this should be very hard [EDIT: for a normal user] to have change whilst keeping their browser open so it should never interupt gaming but it may prove difficult to check. You may be able to check it by logging in, then going through a proxy without first closing your browser. Normally the session id would still be valid and in theory log you in but that extra layer of security should log you out.

Hope that makes sense
Danny

This post has been edited by danny_kay1710: 17 December 2008 - 02:40 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3