session variables and POST

A

Anonymous

Guest
i have a site that is hosted on yahoo.....i want to use session variables to import objects from one page to another....i have successfully done this doing the following

file1: insert.php
<?
session_start();
$sam = "something";
$_SESSION['sam'] = $sam;
?>

file2: select.php
<?
session_start();
$sam = $_SESSION['sam'];
echo $sam;
?>

**i haven't tried this with an object yet, but i assume it will work the same way, anyways....this works great, but when i disable cookies, it doesn't work at all...i am wondering how to do i fix this problem?, can i check to make sure the user is using cookies, and then if they are, then use this method, and if they are not, then have a different approach?, if so, what is this different approach?

i have been searching online, and it seems i can pass sessions through the POST method, but is that ONLY with forms? if not, then how do i implement it?

last question, i normally see websites with something like
http://www.site.php?id=03lswerljsdfl or something like that, which i am assuming is a Query String...is this the same as using sessions, but using the GET method after encrypting it? and what is the best way to pass session variables, Cookies, or POST, or GET

thanks you very much in advance
sam
 
Cookies is by far the easiest way to pass session info.

I have never used PHP sessions with POST/GET methods, but I have used custom sessions with the GET method. We would store the session info in the database and pass the unique session ID to the URL via forms & links.

By the way: You can only store objects in your session if the object's class has been defined before session_start.
Eg, this will work:
Code:
<?php
require_once('myClass.php');
session_start();
$newObject = new myClass();
session_register($newObject);
?>
But this will fail:
Code:
<?php
session_start();
require_once('myClass.php');
$newObject = new myClass();
session_register($newObject);
?>
This also means that auto sessions have to be disabled, otherwise a session will have started before your PHP scripts starts to execute and thus before the required class.

Coditor
 
Back
Top