-1

I've made my search form with html and jquery. When I input a name into the search field, and click search, it checked the MySQL database i specified, and displays any names containing the text in the search field. the url is localhost/players.html because I'm testing it on apache at the moment, and its for a game server player statistics page.

I have the results showing how I want them, in a table with certain information displayed in the columns.

When a result is clicked, I want to display the players statistics on a new page, but I don't want to create and store thousands of pages one for each registered player. So I want it to create a virtual page, or something like that. Where the link is clicked, the URL would be something like /players/PlayerName.html or if that isn't possible maybe players.php?action=getstats(PlayerName) I'm not really sure how to do this or if it's possible.

I want it to work so that if I was to type www.myurl.co.uk/players/PlayerName.html it would show the statistics page for that player, without the html page actually e xisting.

SAFC
  • 314
  • 1
  • 3
  • 11
  • A php book/tutorial might help you. Url arguments can be read by using the global $_GET variable: http://www.w3schools.com/php/php_get.asp – jantimon Oct 20 '11 at 12:05

3 Answers3

2

Do it like this

Create one page called "player.php", this page will receive parameter UserID.

So in you high score table add link for each player to point to this page with the parameter UserID

<a href="/player.php?player_id=xxxxx">Player</a>

when clicked it will go to player.php and you can get your parameter through global $_GET variable like this

$player_id = $_GET["player_id"]

So in you page just select data for that user

$sql = "select * from player_stat where UserID = " . $player_id;

just remember to mysql_escape $player_id before adding it to query in order to avoid SQL Injection

That is easy way, you can do it also with the URL rewriting apache module in order to get friendly URLs like /player/stat/nick-name

but that is more work if your system doesn't support this.

Senad Meškin
  • 13,597
  • 4
  • 37
  • 55
  • Thanks, this worked great and also helped me figure out another problem I was having. Thank you. – SAFC Oct 21 '11 at 10:49
  • This is the right answer and the "standard" way of doing it. I'm a bit paranoid about using $_GET because it's ripe for injection attacks and is a way of letting people access data by guessing at other data values. I would A) use htmlentities on it at the same time you assign it to a variable, B) use 0-filled userIDs (so that each userID has the same number of characters) & check the length of user_ID. If it's not right boot the user (I ban the IP in my more sensitive applications) C) use PDO instead of relying on mysql_escape and such. PDO prevents injection that tacks on "And 1=1" and such – jcanker Oct 12 '16 at 19:24
  • but you could just check if passed value is integer, and problem solved :) – Senad Meškin Oct 12 '16 at 19:41
1

you need to use PHP for this

for example you will send each result to player.php?id=PLAYER_ID and on that page you need to get that player info from the db using the requested ID

check the following links to make it easier for you

http://www.w3schools.com/php/php_mysql_intro.asp

http://www.w3schools.com/php/php_get.asp

trrrrrrm
  • 11,362
  • 25
  • 85
  • 130
0

This is done using mod_rewrite, which is a module for rewriting URLs according to patterns. You often enter these patterns into a file called ".htaccess" file which you put in your web root.

For example:

RewriteEngine on
RewriteRule ^players/([^/]+).html.zip /search.php?playername=$1 [L]

If you go to "/players/MikeRoberts.html", then your PHP script "search.php" will receive the value "MikeRoberts" (which you can access using $_GET['playername']).

Remember: you may need to enable mod_rewrite on your server. See: How to enable mod_rewrite for Apache 2.2 or use Google to find out how to do that.

Community
  • 1
  • 1