PHP Assign tex to session?

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

PHP Assign tex to session?

Post by ayu »

Soooo, my book doesn't tell me this =(

I have a textbox and a submit button.... how do i assign the textbox value to a session so that i can pass it on to the next page, without using post :? ?
"The best place to hide a tree, is in a forest"

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

you cant set the text in a textbox in session unless you make some request first to the server, imagine a textbox
you put some text, you have to send it via post to some script say xyz, now in that script you can set the session variables.

suppose you have a form with textbox named text
you post it to the script submit.php (say)

session_start();
$_SESSION['text']=$_POST['text'];
now on following pages, you can use $_SESSION['text']

otherwise before submitting the form, you may use javascript cookies

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Soooo, between the first and second page i HAVE to use post? =/ basicly?

then i can use session between the rest of my pages?
"The best place to hide a tree, is in a forest"

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

http://www.phpvideotutorials.com/

thay may help there funny :lol: and you learn alot from them duno tho because i only started to learn php last night :)

shamir
Computer Manager
Computer Manager
Posts: 853
Joined: 01 Mar 2007, 17:00
17
Location: NY
Contact:

Post by shamir »

bubzuru wrote:
thay may help there funny :lol: and you learn alot from them duno tho because i only started to learn php last night :)
thanks bubzuru. :lol:

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

This is how I got past the "no global variable" for session WITHOUT enabling globals or whatever it's called.

Code: Select all

session_start();
$ins = $_POST['who'];
$who = $_POST['who'];
$cred = $_POST['cred'];
if ($ins){
if($who&&$cred){
addslashes($who);
addslashes($cred);
$login = mysql_query("SELECT * FROM auth WHERE who='$who' AND cred='$cred'")
	or die ('Error: ' . mysql_error());
if ($row = mysql_fetch_array($login)){
echo 'Welcome, You are logged in br/';
$_SESSION['username'] = $ins;
$_SESSION['length'] = time() + 1400;
echo "User : ".$_SESSION['username']." br";
echo 'script window.location="/in/inside.php" /script';
}
else{
echo 'Wrong User or Password br  input type="button" value="Go Back One Page" onclick="history.back();"></form>';}}
else{
echo 'Fill both entries correctly br';
echo ' form action="index.php" method="index.php"  input type="image" src="/img/submit.png" name="image" width="79" height="25" /form';}
}else{echo 'script window.location="index.php" /script';}

The part to pay attention to is:

Code: Select all

$_SESSION['username'] = $ins;
I don't know why it works because it shouldn't but i'm not complaining :-0
Having the ability to define the session as the username allows for my shoutbox I just made to easily display who 'shouted'.

Good luck man. Php is REALLY easy but the sql can be tricky.
And it looks like crap because I can't put html tags in 0.o
Can't you guys just allow them to be displayed safely?

Post Reply