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('display_errors', 1);
ini_set('log_errors', 0);
ini_set('error_reporting', E_ALL);
session_start();
session_register("sdeneme");
$sdeneme='DENEME';
header("Location: deneme1.php");
?>
SECOND CODE: deneme1.php
<?
ini_set('display_errors', 1);
ini_set('log_errors', 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 10 9475 gr****@cenker.com (Cenker Sisman) wrote in message news:<88**************************@posting.google. com>... FIRST CODE: deneme.php <? ini_set('display_errors', 1); ini_set('log_errors', 0); ini_set('error_reporting', E_ALL);
session_start(); session_register("sdeneme"); $sdeneme='DENEME';
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
On 31 Oct 2003 23:52:12 -0800, ng**********@rediffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths: gr****@cenker.com (Cenker Sisman) wrote in message news:<88**************************@posting.google. com>... FIRST CODE: deneme.php <? ini_set('display_errors', 1); ini_set('log_errors', 0); ini_set('error_reporting', E_ALL);
session_start(); session_register("sdeneme"); $sdeneme='DENEME';
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
Larry Jaques <jake@di\/ersify.com> wrote in message news:<ig********************************@4ax.com>. .. On 31 Oct 2003 23:52:12 -0800, ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) brought forth from the murky depths:
gr****@cenker.com (Cenker Sisman) wrote in message news:<88**************************@posting.google. com>... FIRST CODE: deneme.php <? ini_set('display_errors', 1); ini_set('log_errors', 0); ini_set('error_reporting', E_ALL);
session_start(); session_register("sdeneme"); $sdeneme='DENEME';
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
On 2 Nov 2003 20:29:01 -0800, ng**********@rediffmail.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**********@rediffmail.com (R. Rajesh Jeba Anbiah) brought forth from the murky depths:
>gr****@cenker.com (Cenker Sisman) wrote in message news:<88**************************@posting.google. com>... >> FIRST CODE: deneme.php >> <? >> ini_set('display_errors', 1); >> ini_set('log_errors', 0); >> ini_set('error_reporting', E_ALL); >> >> session_start(); >> session_register("sdeneme"); >> $sdeneme='DENEME'; > > 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_register(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.php.
On cart1.php, we show the basket name and ID based on $basketid value,
then collect delivery address & message vars, form action=cart2.php .
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.
Larry Jaques <jake@di\/ersify.com> wrote in message news:<dl********************************@4ax.com>. .. On 2 Nov 2003 20:29:01 -0800, ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) brought forth from the murky depths:
In past versions of PHP, I used session_register(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.php.
On cart1.php, we show the basket name and ID based on $basketid value, then collect delivery address & message vars, form action=cart2.php .
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
On 3 Nov 2003 21:13:43 -0800, ng**********@rediffmail.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 functionalities 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 --
Larry Jaques <jake@di\/ersify.com> wrote in message news:<fo********************************@4ax.com>. .. On 3 Nov 2003 21:13:43 -0800, ng**********@rediffmail.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 functionalities 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
On 4 Nov 2003 21:01:10 -0800, ng**********@rediffmail.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=mysql_query($sql,$connection)
or die ("Query error:" . mysql_error());
while ($row=mysql_fetch_array($sql_result))
{
$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 --
Larry Jaques <jake@di\/ersify.com> wrote in message news:<65********************************@4ax.com>. .. On 4 Nov 2003 21:01:10 -0800, ng**********@rediffmail.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.php">
<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.php">
<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='".$basketid."'";
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
On 5 Nov 2003 20:44:56 -0800, ng**********@rediffmail.com (R. Rajesh
Jeba Anbiah) brought forth from the murky depths: Larry Jaques <jake@di\/ersify.com> wrote in message news:<65********************************@4ax.com>. .. On 4 Nov 2003 21:01:10 -0800, ng**********@rediffmail.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:
Thank you for the spoonfeeding. My arms were getting tired from
all the flailing about I've been doing for weeks. ;)
<!-- 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.php"> <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>
Ah, it finally sinks in. I hadn't fully grokked your use of
the hidden form, didn't know you had meant to reiterate them
on subsequent pages. NOW I see how that works without sessions.
<!-- 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>
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='".$basketid."'";
I have been picking that up from examples in this and other
forums lately and now understand why. I can also preprocess
raw vars prior to query, another good thing for added safety. 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.
I guess PHP and I have a different idea as to the definition
of the term "SUPERGLOBAL." Time for me to reread the online docs. I can't visualize PHP code yet like I do with HTML.
So, IMHO learn PHP bit more.
I fully intend to, thanks. Like I said, all of my earlier
clients had membership databases so all the PHP work I had
done prior to this was simple query/output of data.
Rasmus Lerdorf's book "Programming PHP" is now in my library
for immediate consumption.
Thanks again for all your help.
-- Friends Don't Let Friends Eat Turkey and Drive -- This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by Philip D Heady |
last post: by
|
117 posts
views
Thread by Peter Olcott |
last post: by
|
28 posts
views
Thread by Jon Davis |
last post: by
|
6 posts
views
Thread by Ammar |
last post: by
|
16 posts
views
Thread by Dany |
last post: by
|
2 posts
views
Thread by Mike Collins |
last post: by
| |
1 post
views
Thread by Kurda Yon |
last post: by
| | | | | | | | | | | |