473,574 Members | 2,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session_registe r problem

My problem is I cannot set session variables correctly.
I have tried both PHP 4.2.2 and 4.3.3, with register_global is ON.
But I cannot manage to see the desired result.
My configuration for PHP 4.2.2 is
Redhat Linux 8.0
apache_1.3.28
php 4.2.2

What I am doing wrong ?
Thank you in advance,
Cenker Sisman

FIRST CODE: deneme.php
<?
ini_set('displa y_errors', 1);
ini_set('log_er rors', 0);
ini_set('error_ reporting', E_ALL);

session_start() ;
session_registe r("sdeneme");
$sdeneme='DENEM E';
header("Locatio n: deneme1.php");
?>

SECOND CODE: deneme1.php

<?
ini_set('displa y_errors', 1);
ini_set('log_er rors', 0);
ini_set('error_ reporting', E_ALL);
session_start() ;
echo ($sdeneme);
?>

BROWSER OUTPUT
Notice: Undefined variable: sdeneme in /www1/htdocs/deneme1.php on line 8
Jul 17 '05 #1
10 9579
gr****@cenker.c om (Cenker Sisman) wrote in message news:<88******* *************** ****@posting.go ogle.com>...
FIRST CODE: deneme.php
<?
ini_set('displa y_errors', 1);
ini_set('log_er rors', 0);
ini_set('error_ reporting', E_ALL);

session_start() ;
session_registe r("sdeneme");
$sdeneme='DENEM E';


It is old style. Instead try $_SESSION['foo'] = "new value";

And then in second script read as
echo $_SESSION['foo'];

---
"He who created the god was a fool; he who spreads his name is a
scoundrel and he who worships him is a barbarian."---Periyar, Famous
Tamil Rationalist
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
On 31 Oct 2003 23:52:12 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:
gr****@cenker. com (Cenker Sisman) wrote in message news:<88******* *************** ****@posting.go ogle.com>...
FIRST CODE: deneme.php
<?
ini_set('displa y_errors', 1);
ini_set('log_er rors', 0);
ini_set('error_ reporting', E_ALL);

session_start() ;
session_registe r("sdeneme");
$sdeneme='DENEM E';


It is old style. Instead try $_SESSION['foo'] = "new value";

And then in second script read as
echo $_SESSION['foo'];


How do you register a session var without a value using the new
style? All the examples I've seen have values. I want it to be a
var, not a value. Would I use something like this:

$_SESSION['foo'] = $foonew;

and fill $foonew later in the form?
--
Music washes away from the soul the dust of everyday life.
---- --Unknown
Jul 17 '05 #3
Larry Jaques <jake@di\/ersify.com> wrote in message news:<ig******* *************** **********@4ax. com>...
On 31 Oct 2003 23:52:12 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:
gr****@cenker. com (Cenker Sisman) wrote in message news:<88******* *************** ****@posting.go ogle.com>...
FIRST CODE: deneme.php
<?
ini_set('displa y_errors', 1);
ini_set('log_er rors', 0);
ini_set('error_ reporting', E_ALL);

session_start() ;
session_registe r("sdeneme");
$sdeneme='DENEM E';


It is old style. Instead try $_SESSION['foo'] = "new value";

And then in second script read as
echo $_SESSION['foo'];


How do you register a session var without a value using the new
style? All the examples I've seen have values. I want it to be a
var, not a value. Would I use something like this:

$_SESSION['foo'] = $foonew;

and fill $foonew later in the form?


Sorry, I couldn't understand what do you mean here... Could you
provide more details? And, what is the purpose of your question?

---
"He who created the god was a fool; he who spreads his name is a
scoundrel and he who worships him is a barbarian."---Periyar, Famous
Tamil Rationalist
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4
On 2 Nov 2003 20:29:01 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:
Larry Jaques <jake@di\/ersify.com> wrote in message news:<ig******* *************** **********@4ax. com>...
On 31 Oct 2003 23:52:12 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:
>gr****@cenker. com (Cenker Sisman) wrote in message news:<88******* *************** ****@posting.go ogle.com>...
>> FIRST CODE: deneme.php
>> <?
>> ini_set('displa y_errors', 1);
>> ini_set('log_er rors', 0);
>> ini_set('error_ reporting', E_ALL);
>>
>> session_start() ;
>> session_registe r("sdeneme");
>> $sdeneme='DENEM E';
>
> It is old style. Instead try $_SESSION['foo'] = "new value";
>
> And then in second script read as
>echo $_SESSION['foo'];


How do you register a session var without a value using the new
style? All the examples I've seen have values. I want it to be a
var, not a value. Would I use something like this:

$_SESSION['foo'] = $foonew;

and fill $foonew later in the form?


Sorry, I couldn't understand what do you mean here... Could you
provide more details? And, what is the purpose of your question?


In past versions of PHP, I used session_registe r(foo) to register a
var which did not need a value at the time of registration. I filled
in that information later, from the form input. All the new style
$_SESSION vars, such as your example above, are shown with values.
Current versions are PHP/4.3.2, Apache/1.3.27, MySQL/4.0.15.

My question was "Must I fill in a value at the time of session var
creation?"

Here is the flow of the site:

Gift basket page contains "add to cart" button with $basketid value
"1", $bname value "Surprise", and form action=cart1.ph p.

On cart1.php, we show the basket name and ID based on $basketid value,
then collect delivery address & message vars, form action=cart2.ph p .

On cart2.php, we use $basketid to grab shipping fees from the database
and collect a delivery date. form action cart3.php

On cart3.php, we display the previously collected info and prepare for
checkout or additions.

checkout.php will (once figured out) add the data to the database
and send email (instead of charging credit cards) so she can call
for the card number.
New Question: What is the best way to register, store, and be able
to display that var data with "$_SESSION" ? Currently, I start the
session on the cart1 page. Should I grab $bname and $basketid via
$_POST there, then use $_SESSION vars on the rest of the pages?
Almost all of my (self-taught) PHP/MySQL work in the past involved
finding and displaying data from existing flatfile (membership type)
databases so this is all new to me. I fed databases new data from CSV
files using the "LOAD DATA LOCAL INFILE" method.

Numerous books haven't solidified all the concepts for me yet, so I'm
choking a bit on this shopping cart and how to finalize this site. A
download of the scart (simplecart) class file from Manuel Lemos' PHP
Classes site looks promising but I'm not sure of the insertion points.

I welcome any help I can get. Thanks.

Jul 17 '05 #5
Larry Jaques <jake@di\/ersify.com> wrote in message news:<dl******* *************** **********@4ax. com>...
On 2 Nov 2003 20:29:01 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths: In past versions of PHP, I used session_registe r(foo) to register a
var which did not need a value at the time of registration. I filled
in that information later, from the form input. All the new style
$_SESSION vars, such as your example above, are shown with values.
Current versions are PHP/4.3.2, Apache/1.3.27, MySQL/4.0.15.

My question was "Must I fill in a value at the time of session var
creation?"
Don't create the session var unless you value to store. Or just
store "" while creating the var.

Here is the flow of the site:

Gift basket page contains "add to cart" button with $basketid value
"1", $bname value "Surprise", and form action=cart1.ph p.

On cart1.php, we show the basket name and ID based on $basketid value,
then collect delivery address & message vars, form action=cart2.ph p .

On cart2.php, we use $basketid to grab shipping fees from the database
and collect a delivery date. form action cart3.php

On cart3.php, we display the previously collected info and prepare for
checkout or additions.

checkout.php will (once figured out) add the data to the database
and send email (instead of charging credit cards) so she can call
for the card number.
New Question: What is the best way to register, store, and be able
to display that var data with "$_SESSION" ? Currently, I start the
session on the cart1 page. Should I grab $bname and $basketid via
$_POST there, then use $_SESSION vars on the rest of the pages?
IMHO, in this case, pass the ids via hidden form variables and
grab it via $_POST. I don't see any necessity for the $_SESSION here
in this case.

The reason why people go for session in shopping cart is: they
will allow the user to add the products into basket (which is nothing
but session vars). And during checkout, they'll process the content of
the basket (that is grab the stored info from the session vars). See
http://groups.google.com/groups?thre...1748%40php.net

Almost all of my (self-taught) PHP/MySQL work in the past involved
finding and displaying data from existing flatfile (membership type)
databases so this is all new to me. I fed databases new data from CSV
files using the "LOAD DATA LOCAL INFILE" method.

Numerous books haven't solidified all the concepts for me yet, so I'm
choking a bit on this shopping cart and how to finalize this site. A
download of the scart (simplecart) class file from Manuel Lemos' PHP
Classes site looks promising but I'm not sure of the insertion points.


Try osCommerce ( http://www.oscommerce.com/ ). Looking at the
functionalities and source code may help you better.

---
"Success = 10% sweat + 90% tears"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #6
On 3 Nov 2003 21:13:43 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:
My question was "Must I fill in a value at the time of session var
creation?"
Don't create the session var unless you value to store. Or just
store "" while creating the var.


Ah, got it. Thanks.

IMHO, in this case, pass the ids via hidden form variables and
grab it via $_POST. I don't see any necessity for the $_SESSION here
in this case.
I'm primarily storing data for several pages, displaying just a few,
and then working with them all and saving to database at the end.
Don't all hidden vars use known values? Most of these would be filled
in as the client gets to the page. Or were you referring to the name
and ID fields, which I did know on the initial page?

The reason why people go for session in shopping cart is: they
will allow the user to add the products into basket (which is nothing
but session vars). And during checkout, they'll process the content of
the basket (that is grab the stored info from the session vars). See
http://groups.google.com/groups?thre...1748%40php.net


OK, so $_POST vars will work for me all pages except the cart display
page, where I'll use and manipulate $_SESSION vars? I think it's
starting to sink in through this thick skull of mine.

If session vars are most often used, do you know how they are doing
the multiple carts on http://www.godiva.com ? I realize that they're
using the dreaded lurgy (.asp) on that site, but they stack the carts
on top of one another to send gifts to multiple addressees/addresses.
Would that be a matter of creating additional objects on the page or
second/third sessions, or ?

Classes site looks promising but I'm not sure of the insertion points.


Try osCommerce ( http://www.oscommerce.com/ ). Looking at the
functionalitie s and source code may help you better.


I downloaded that and nearly soiled my pants when I saw that the
unzipped program had OVER 1,000 associated files, mostly PHP.
Where would one START? =:0 And, of course, I'm on a Winbox and
don't have a local box with LAMP on it for easier testing. <sigh>

Thanks for your help. I'll keep plugging along.
-- Friends Don't Let Friends Eat Turkey and Drive --
Jul 17 '05 #7
Larry Jaques <jake@di\/ersify.com> wrote in message news:<fo******* *************** **********@4ax. com>...
On 3 Nov 2003 21:13:43 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:

The reason why people go for session in shopping cart is: they
will allow the user to add the products into basket (which is nothing
but session vars). And during checkout, they'll process the content of
the basket (that is grab the stored info from the session vars). See
http://groups.google.com/groups?thre...1748%40php.net
OK, so $_POST vars will work for me all pages except the cart display
page, where I'll use and manipulate $_SESSION vars? I think it's
starting to sink in through this thick skull of mine.

If session vars are most often used, do you know how they are doing
the multiple carts on http://www.godiva.com ?


If I guess right, they use the same logic as stated in
http://groups.google.com/groups?thre...1748%40php.net

I hope, you can get this logic by trial and error.
I realize that they're
using the dreaded lurgy (.asp) on that site, but they stack the carts
on top of one another to send gifts to multiple addressees/addresses.
Would that be a matter of creating additional objects on the page or
second/third sessions, or ?

Classes site looks promising but I'm not sure of the insertion points.


Try osCommerce ( http://www.oscommerce.com/ ). Looking at the
functionalitie s and source code may help you better.


I downloaded that and nearly soiled my pants when I saw that the
unzipped program had OVER 1,000 associated files, mostly PHP.
Where would one START? =:0 And, of course, I'm on a Winbox and
don't have a local box with LAMP on it for easier testing. <sigh>


FYI, I too work in WAMP. I couldn't understand your problem. They
have more plugins; it is so generalized, and so they have more codes.
You just see the page that use cart and then look at the source. If
you do Google, you may get simple PHP shopping cart script (I hope).

---
"If there is a God, he must be a sadist!"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #8
On 4 Nov 2003 21:01:10 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths:
OK, so $_POST vars will work for me all pages except the cart display
page, where I'll use and manipulate $_SESSION vars? I think it's
starting to sink in through this thick skull of mine.
Well, I tried my thoughts above and it doesn't work. Data entered
from the first form (product page) travels to the first cart page
but not beyond. How do I carry those vars through the cycle without
a session?!?

Vars $basketid and $bname from the product page go to Cart1.php and
show up as #"2" and "Enjoy Paradise with fresh fruit" as expected.
Cart1 adds delivery address request and messages which show up on
the next page, but I've lost the $basketid and $bname data whether
I call it with the original var name, rename it, or use $_POST[bname].
That means the query doesn't work and I come up empty. (see below)

(snip of logon to DB)
$sql="select * from baskets where bid=\"$_POST[basketid]\" ;";
$sql_result=mys ql_query($sql,$ connection)
or die ("Query error:" . mysql_error());
while ($row=mysql_fet ch_array($sql_r esult))
{
$bid2 = $row["bid"];
$bnam2 = $row["bname"];
$bprice= $row["bprice"];
$hono = $row["honolulu"];
$oahu = $row["oahu"];
$prioi = $row["priorityoi "];
$prim = $row["prioritym"];
$fed = $row["fedex"];
}

I spotted that extra space after the \" at the end of the query
and removed it with no change. What am I missing? Are the
$_POST vars only global to a single form? If so, how do I use
them for this 4-page scheme?

If session vars are most often used, do you know how they are doing
the multiple carts on http://www.godiva.com ?
If I guess right, they use the same logic as stated in
http://groups.google.com/groups?thre...1748%40php.net

I hope, you can get this logic by trial and error.
Is the "foreach" line the main concept? I can't visualize PHP code yet
like I do with HTML.
// - Show
if( isset( $_SESSION['aBasket'] ) ) {
foreach ( $_SESSION['aBasket'] as $key=>$val ) {
echo "$key ";
}
}
FYI, I too work in WAMP. I couldn't understand your problem. They
have more plugins; it is so generalized, and so they have more codes.
You just see the page that use cart and then look at the source. If
you do Google, you may get simple PHP shopping cart script (I hope).


Macromedia shows a simple one I might try to convert.

Thanks.
-- Friends Don't Let Friends Eat Turkey and Drive --
Jul 17 '05 #9
Larry Jaques <jake@di\/ersify.com> wrote in message news:<65******* *************** **********@4ax. com>...
On 4 Nov 2003 21:01:10 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths: Well, I tried my thoughts above and it doesn't work. Data entered
from the first form (product page) travels to the first cart page
but not beyond. How do I carry those vars through the cycle without
a session?!?
Though I feel guilty to spoonfeed you, here is the sample code:

<!--page1.php -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Page1</TITLE>
<META http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</HEAD>
<BODY>
<FORM name="form1" method="post" action="page2.p hp">
<INPUT name="a" type="text" id="a">
<INPUT name="b" type="text" id="b">
<INPUT type="submit" name="Submit" value="Go to Page 2">
</FORM>
</BODY>
</HTML>
<!-- page2.php -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Page2</TITLE>
<META http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</HEAD>
<BODY>
<?php
$a = isset($_POST['a']) ? $_POST['a'] : '';
$b = isset($_POST['b']) ? $_POST['b'] : '';
?>
<FORM name="form1" method="post" action="page3.p hp">
<INPUT name="a" type="hidden" id="a" value="<?=$a?>" >
<INPUT name="b" type="hidden" id="b" value="<?=$b?>" >
<INPUT name="c" type="text" id="c" value="">
<INPUT type="submit" name="Submit" value="Go to Page 3">
</FORM>
</BODY>
</HTML>
<!-- page3.php -->
<HTML>
<HEAD>
<TITLE>Page 3</TITLE>
<META http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</HEAD>
<BODY>
<?php
print_r($_POST) ;
?>
</BODY>
</HTML>

Vars $basketid and $bname from the product page go to Cart1.php and
show up as #"2" and "Enjoy Paradise with fresh fruit" as expected.
Cart1 adds delivery address request and messages which show up on
the next page, but I've lost the $basketid and $bname data whether
I call it with the original var name, rename it, or use $_POST[bname].
That means the query doesn't work and I come up empty. (see below)

(snip of logon to DB)
$sql="select * from baskets where bid=\"$_POST[basketid]\" ;";
Always for code cleanliness, test the presence of POST variable
like:
$basketid = isset($_POST['basketid']) ? $_POST['basketid'] : 0;
And then use the query like
$sql="select * from baskets where bid='".$basketi d."'";
I spotted that extra space after the \" at the end of the query
and removed it with no change. What am I missing? Are the
$_POST vars only global to a single form?
Yes.
If so, how do I use
them for this 4-page scheme?
See my mock codes.
If session vars are most often used, do you know how they are doing
the multiple carts on http://www.godiva.com ?

If I guess right, they use the same logic as stated in
http://groups.google.com/groups?thre...1748%40php.net

I hope, you can get this logic by trial and error.


Is the "foreach" line the main concept?


Oops! This is not a working shopping cart script. It just
explains the logic behind shopping cart system.
I can't visualize PHP code yet
like I do with HTML.
So, IMHO learn PHP bit more.
// - Show
if( isset( $_SESSION['aBasket'] ) ) {
foreach ( $_SESSION['aBasket'] as $key=>$val ) {
echo "$key ";
}
}


This is just a mock code to show the content of the basket. You
need to write more codes if you want to add quantity, price, etc.

---
"The world is too dangerous to live in—not because of the people who
do evil, but because of the people who sit and let it happen"---Albert
Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2797
by: Philip D Heady | last post by:
is this valid? session_register('variable1','variable2','variable3','etc'); If not, how can you register a bunch all at once without having to use a line for each variable?
117
7130
by: Peter Olcott | last post by:
www.halting-problem.com
28
5189
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I...
6
3791
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is...
16
4889
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be...
2
4539
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am...
1
1201
by: jx2 | last post by:
whats wrong with that: PHP code: <?php; if(!$Tour){$Tour= new tournament();session_register("Tour");} $Tour->echodouble(); class tournament { var $nr,$TF; //$TF - keep files' paths
1
2333
by: Kurda Yon | last post by:
Hi All, is that OK if I declare the same variable in the same file several times? For example somewhere in the beginning of a file I have session_register("cat") and than, somewhere in the middle of the file, I have again session_register("cat"). Can the second declaration destroy the value of the variable cat? Is that OK if I...
6
6022
anfetienne
by: anfetienne | last post by:
hi ive been using a login code which uses sql & db its quite simple and has been working great.....but as i have just gone to do a final test on the site i've built starting from the login page i get the following error message... "Warning: session_register() : Cannot send session cache limiter - headers already sent (output started at...
0
7835
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7753
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5332
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2265
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1096
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.