Page 1 of 1
Questions on Sessions in php
Posted: Wed Nov 17, 2010 11:17 pm
by Baseball435
Hey guys. Well I have a question on making a session. I'm trying to make it so that when they Click a link it sets the session to the houseid.
Code: Select all
<a href="playerhouse.php?Id=<?php echo $houseid ?>$housename</a>
That is the code that I have an I have a while loop so that it posts all of the houses on that map. How would I set a session so that when they click one of the house links it sets a session to the $houseid. Thanks!
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 3:05 am
by hallsofvallhalla
why would you want to set a session? Just carry the houseid through a POST or GET variable.
Look at your authenticate.php. It makes a session with username.
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 3:32 am
by Baseball435
How would I do that though? Would I name the link as something? And I actually am making this from complete scratch, like I didn't use any of your source files so I don't have a authenticate.php file
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 6:01 am
by Callan S.
Code: Select all
if (isset($_GET['something'])) echo "You passed ".$_GET['something']." through<p>";
echo "<a href='?something=5'>Pass something through post</a><br>";
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 11:35 am
by Baseball435
See but where would actually set that get part? Because I want it kind of like an on-click type of function where I will set a session that equals to the houseid of the link clicked
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 2:00 pm
by hallsofvallhalla
to keep your data more secure you could use post
build the button
page where you would click to go to house
Code: Select all
echo "<form action='myhouse.php' method='post' >
<center><input type='submit' value='Go to house'></center>
<input type='hidden' name='houseid' value='$houseid'>
</form>";
myhouse.php
now lets say you wanted to go to another page from myhouse.php and bring over the $houseid and lets say you wanted to also wanted the player to choose how much gold to add to the house inventory
simply repeat the first code
Code: Select all
echo "<form action='deposithouse.php' method='post' >
How Much gold would you like to deposit? <input type='text' name='gold' size='11'> Gold<br>
<input type='hidden' name='houseid' value='$houseid'>
<center><input type='submit' value='Deposit Money'></center>
</form></tr>";
Then on deposithouse.php
Code: Select all
$houseid=$_POST['houseid'];
$gold=$_POST['gold'];
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 4:26 pm
by Baseball435
rofl i know thatttt, i know how to make buttons and use post or i wouldnt have gotten this far in my project. But what i mean is setting a session/post/get when a person presses a link like
that. Thats what im trying to figure out
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 6:58 pm
by hallsofvallhalla
that is what i was showing you. Am i not understanding what you mean?
Code: Select all
<a href="home.php?houseid=$houseid">home</a>
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 8:04 pm
by Baseball435
I think I'm not understanding what you mean

do you mean like you have they've link on one page and then that get function on the next?
Re: Questions on Sessions in php
Posted: Thu Nov 18, 2010 9:44 pm
by Callan S.
You know you can take the contents of a get or post and make a $_SESSION equal it? That's pretty much it?