Forum Moderators: coopster
thanks any help would be great
and welcome to webmasterworld.
uhi, thats a strange problem. do you know why you can't get sessions to work?
do you have
session_start();
in every php file you use? you have to put it at the top. it should be the first thing you call in every php file.
if you really have no opportunity to get sessions to work i can only think of a solution by passing the info to all urls.
but this means, you have to change the urls in the file on the fly.
e.g. normal link to the homepage looks like this "/index.php". now someon adds smth to the cart. now every link on the page looks like this "/index.php?prod[][12]=2" whereas 12 is the product id and 2 is the quantity. if the user selects a second product it would look like this "/index.php?prod[][12]=2&prod[][343]=1". but this gets really ugly the bigger the cart gets :D
hope this helps.
barn
I got sessions to work, now I can't seem to make them remember what the user selected. Once the form gets submitted it echos what they had typed, but once I refresh the page or goto a different page and come back to it, it doesn't remember it anymore. I think its happening becuase I am relying on POST, but I don't know what else to use.. i skip the title tags and html tags just here
here is a test code from the two files
test.php
<body>
<form method="post" action="test2.php">
<input type="text" name="textbox">
<input name="" type="submit" value="enter">
</form>
</body>
code test2.php
<?php session_start();
$_SESSION["check"] = $_POST['textbox'];
?>
<html>
<body>
<?php echo 'what was the session value' . $_SESSION["check"];?>
</body>
</html>
thats just a small prob. you write the $_SESSION every time. and if you refresh the $_POST array should be empty, because you didn't submit it again. so you wirte an empty value in the session.
so you have to check if there was really a post done.
this should work:
if(count($_POST) >= 1) {
$_SESSION["check"] = $_POST['textbox'];
}
this time it gets only written, if there was a real post.
barn
I appreciate all your time and help. I am reading and practicing code like crazy to learn this language, but just am wayyyy to new....
here you can find a manual:
[de.php.net...]
here some examples you can use:
setcookie ("prod[12]", 2, time()+86400);
setcookie ("prod[364]", 1, time()+86400);
86400 seconds = 1 day. so this cookie will be valid for 1 day.
to get the cookie values use:
if (isset($_COOKIE['prod'])) {
foreach ($_COOKIE['prod'] as $ProdId => $iAmount) {
put_whatever_you_have_to_do_here
}
}
barn