PHP and sessions 
Author Message
 PHP and sessions

I have been trying to write a script that would save an array in a PHP
session.  I have looked at all the documentation, but whatever I try, my
page does not seem to work.

Recently I have gone as far as to try to get a simple session to work,
to no avail.  I'm starting to wonder if there is some setting I have to
have my host set to get sessions to work.  I know they are using a
version of PHP above 4.

I am going to paste the code below, but keep in mind my example is a
mess.  I have tried $_Session, $HTTP_SESSION_VARS, session_register(),
etc.  I have also tried all the examples on php.net's documentation, and
an example on webmonkey.com.  I know that the current version of my
example does not work, but if anyone can see something I am doing wrong

- Please feel free to make as many suggestions as your heart desires.

Thanks in advance...

<?php
error_reporting(E_ALL);

session_start();

if (!isset($_SESSION['gbcartarray'])) {
   $gbcartarray = $_SESSION['gbcartarray'];
   //$gbcartarray = array();
   print("<br />array has been registered<br />");

Quote:
} else {

   print("<br />array was registered, contents of gbcartarray:<br />");
   foreach($gbcartarray as $key=>$value) {
     print("The value of index $key is $value<br />");
   }

Quote:
}

$gbcartarray2 = $gbcartarray;

?>

<html>

<form action="<?=$PHP_SELF?>" method="get">
   <input type="text" name="newname" />
   <input type="submit" value="go" />
</form>

<?php

//testing that I have an actual array
$gbcartarray2[] = "ignore1";
$gbcartarray2[] = "ignore2";

if ( isset($newname) ) {
    $gbcartarray2[] = $newname;

Quote:
}

if (!is_array($gbcartarray2)) {
    print("not an array<br>");
Quote:
} else {

    foreach($gbcartarray2 as $key=>$value) {
      print("The value of index $key is $value<br />");
    }

Quote:
}

?>

<br /><br />

<a href = "<?=$PHP_SELF?>" onClick="<?=session_destroy()?>">Clear
contents of cart</a><br>

</html>



Mon, 27 Jun 2005 12:53:01 GMT  
 PHP and sessions

Quote:

> if (!isset($_SESSION['gbcartarray'])) {
>    $gbcartarray = $_SESSION['gbcartarray'];

This does not seem to make sense: if $_SESSION['gbcartarray'] is NOT
set, how can you assign its value to another variable?  Do you mean the
opposite ($_SESSION['gbcartarray'] = $gbcartarray)?

Just the first thing I noticed, have to leave for work now.

JP

--




Mon, 27 Jun 2005 14:00:49 GMT  
 PHP and sessions
Thanks for the reply.  I know that line is incorrect.  It was the
result of a late night and trying anything to get it to work.  I guess
I didn't review the code enough before I pasted it.

anyway, I was trying to set a session variable if it was not set.  For
some reason I am always registering the variable anytime I load the
page.


Quote:


> > if (!isset($_SESSION['gbcartarray'])) {
> >    $gbcartarray = $_SESSION['gbcartarray'];

> This does not seem to make sense: if $_SESSION['gbcartarray'] is NOT
> set, how can you assign its value to another variable?  Do you mean the
> opposite ($_SESSION['gbcartarray'] = $gbcartarray)?

> Just the first thing I noticed, have to leave for work now.

> JP



Tue, 28 Jun 2005 01:25:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. PHP and sessions...

2. python+php HTTP sessions

3. php keeps starting new sessions rather than use current session

4. php session variables on multiple pages

5. Sessions mit PHP

6. How long does PHP store variables and sessions?

7. PHP Session in Windows - Please help...

8. PHP session

9. Are session vars evil in PHP?

10. PHP Sessions and SSL

11. php install problem - probably to do with session/cookie storage, or IIS authentication

12. php 4.3 and sessions

 

 
Powered by phpBB® Forum Software