Questions on Sessions in php

For discussions about game development that does not fit in any of the other topics.
Post Reply
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Questions on Sessions in php

Post 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!
Last edited by Baseball435 on Thu Nov 18, 2010 11:34 am, edited 1 time in total.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Questions on Sessions in php

Post 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.
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Questions on Sessions in php

Post 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
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Questions on Sessions in php

Post 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>";
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Questions on Sessions in php

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Questions on Sessions in php

Post 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

Code: Select all

$houseid=$_POST['houseid'];

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'];

Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Questions on Sessions in php

Post 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

Code: Select all

<a href="home.php">home</a>
that. Thats what im trying to figure out
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Questions on Sessions in php

Post 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>

Code: Select all

$houseid = $_GET['houseid'];
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Questions on Sessions in php

Post by Baseball435 »

I think I'm not understanding what you mean :P do you mean like you have they've link on one page and then that get function on the next?
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Questions on Sessions in php

Post 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?
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Post Reply

Return to “General Development”