Log in

View Full Version : Sessions...



Rockonmetal
08-30-2007, 10:35 PM
I am looking for a session tutorial or how to make a session remember the contents of a form input...

I don't know how to do this but I can easily get some code... Note the information has to stored like this
1. Form where stuff is put in...
2. Validation page
3. Upload *WHERE DATA IS RECALLED*

I think this can be done by doing this, though I haven't found a tutorial on this...

Thanks!

Twey
08-30-2007, 11:15 PM
Firstly, call session_start() at the top of any page where you intend to use sessions. Secondly, read and write to and from $_SESSION as if it were a normal associative array. Thirdly... oh wait, that's it :p

Rockonmetal
08-30-2007, 11:30 PM
Ok i already had session start, thats ok i didn't say that in my first part, but I really don't know how to do $_SESSION so what would that look like?
if its like this *but a without the errors*

$_SESSION = "$input";$_SESSION = "$input2";
I know that is most likely wrong but if its somethign like that I will be able to figure it out...
But I have no idea how to do this...

THANKS!

Twey
08-31-2007, 12:15 AM
http://www.tizag.com/phpT/arrays.php

Rockonmetal
08-31-2007, 01:11 AM
Hey I tried it but I couldn't get it... how would I put this code in?
I got three pages... I don't how to do this sorry, and I am really only good at if statements and variables...
Thanks a lot man...

Twey
08-31-2007, 08:29 AM
$_SESSION['input1'] = $_POST['input1'];Or store everything:
foreach($_POST as $k => $v)
$_SESSION[$k] = $v;

Rockonmetal
08-31-2007, 12:09 PM
ok i'll try the first one because the second one doesn't make sense, but thats probably cuz I just woke up lol...

boogyman
08-31-2007, 12:27 PM
foreach($_POST as $k => $v)
$_SESSION[$k] = $v;[/code]
foreach is a loop

$k = key
$v = value

of the array.. I am sure you have seen this type of notation before, you just didnt know what it meant


website.com/index.php?do=login&user=boogyman

I am sure you would recognize that alot easier if i put it into this type of format


$_GET['do'] = 'login';
$_GET['user'] = 'boogyman';


that is using the get method. the post method uses the same principles, but you cannot see the extra characters, you would only see the website.com/search.php

another way to define an array is


$array("do" =>"login", "user"=>"boogyman");


that explicitly defines the key where an array like this


$array("login", "boogyman");

would have the defaulted numerical key... so to see the contents of the $array now it would look like this


$array[0] = "login";
$array[1] = "boogyman";


as you can see it could potentially create lots of problems by having a numerical keyset rather then a custom one. that is why we use the "name" attribute in our forms, so its alot easier to read and instruct the processing of the page faster and more accurately and efficiently.

Rockonmetal
08-31-2007, 04:04 PM
Ok, I sorta got that, but not so much... I put in this:

$_SESSION['input1'] = $_POST['input1'];
$_SESSION['input2'] = $_POST['input2'];
$_SESSION['input3'] = $_POST['input3'];
$_SESSION['input4'] = $_POST['input4'];
$_SESSION['input5'] = $_POST['input5'];
$_SESSION['input6'] = $_POST['input6'];
$_SESSION['input7'] = $_POST['input7'];
$_SESSION['input8'] = $_POST['input8'];
$_SESSION['input9'] = $_POST['input9'];
$_SESSION['input10'] = $_POST['input10'];
In the validate page (second page)
What would I put to make so the data from the form is turned back into a variable... like heres an example...
1. Form page data input into forms
2. Validation Page data checked
3. *Problem Area* Write Data from page 1 to specific file...

I don't know how to do that... that is why I asked for help, I looked in your post boogyman i couldn't find or see anything that said about recalling information, really though most the stuff you said was over my head...

Twey
08-31-2007, 08:11 PM
Why do you name all your inputs input#? That's a really stupid name, it doesn't tell you anything about what the input actually passes. And yes, the loop would be better here.

Rockonmetal
09-01-2007, 02:05 AM
I name them input# because its just easier to do that later on and plus its really easy to copy and paste instead of having to type in the name of the input...
Though I have no idea how to do loops so if anyone could help me that would be spectacular!!!
All i need is for the session data to either turn back into variables or for it to be able to be written into a file... i just don't know how to do that process...
heres as far as i got before i'm stumpped...

$_SESSION['input1'] = $_POST['input1'];
$_SESSION['input2'] = $_POST['input2'];
$_SESSION['input3'] = $_POST['input3'];
$_SESSION['input4'] = $_POST['input4'];
$_SESSION['input5'] = $_POST['input5'];
$_SESSION['input6'] = $_POST['input6'];
$_SESSION['input7'] = $_POST['input7'];
$_SESSION['input8'] = $_POST['input8'];
$_SESSION['input9'] = $_POST['input9'];
$_SESSION['input10'] = $_POST['input10'];

Twey
09-01-2007, 12:34 PM
I name them input# because its just easier to do that later on and plus its really easy to copy and paste instead of having to type in the name of the input...If you find yourself copying and pasting code in any language, you're doing something wrong.
Though I have no idea how to do loops so if anyone could help me that would be spectacular!!!I just wrote it for you!
All i need is for the session data to either turn back into variables or for it to be able to be written into a fileYou can access the data in the page where you need to access it as e.g. $_SESSION['input1'].

boogyman
09-01-2007, 04:44 PM
Though I have no idea how to do loops so if anyone could help me that would be spectacular!!! I just wrote it for you!

Me thinks you are blind :)



foreach($_POST as $k => $v)
$_SESSION[$k] = $v;