Generate dynamic page based on link clicked.
- killfrog47
- Posts: 106
- Joined: Tue Mar 12, 2013 2:52 am
- Location: Tempe, AZ
- Contact:
Generate dynamic page based on link clicked.
Hello all so here is my problem. I am making a page for my minecraft members just like http://somethingcraft.co.uk/stats.html Now the one problem I am having is that i dont know how to get the stats.html?player=playername I have been through google many times but im not sure what to search to get good answers. Any pointers?
Re: Generate dynamic page based on link clicked.
Hi.
It's not all that difficult
If you had something like:
[syntax=text]player.php?player=test1&foo=1&what=loljk[/syntax]
you could access it all in code like so:
[syntax=php]<?php
echo $_GET['player']; // Displays "test1"
echo $_GET['foo']; // Displays "1"
echo $_GET['what']; // Displays "loljk"
?>[/syntax]
Just like that!
Any more questions or do you have it down pat?
It's not all that difficult
If you had something like:
[syntax=text]player.php?player=test1&foo=1&what=loljk[/syntax]
you could access it all in code like so:
[syntax=php]<?php
echo $_GET['player']; // Displays "test1"
echo $_GET['foo']; // Displays "1"
echo $_GET['what']; // Displays "loljk"
?>[/syntax]
Just like that!
Any more questions or do you have it down pat?
- killfrog47
- Posts: 106
- Joined: Tue Mar 12, 2013 2:52 am
- Location: Tempe, AZ
- Contact:
Re: Generate dynamic page based on link clicked.
Helx wrote:Hi.
It's not all that difficult
If you had something like:
[syntax=text]player.php?player=test1&foo=1&what=loljk[/syntax]
you could access it all in code like so:
[syntax=php]<?php
echo $_GET['player']; // Displays "test1"
echo $_GET['foo']; // Displays "1"
echo $_GET['what']; // Displays "loljk"
?>[/syntax]
Just like that!
Any more questions or do you have it down pat?
That helps out alot actually! So my link on my website could look something like this [syntax=xhtml]echo '<a href="player.php?player='.$row['players'].'">'.$row['players'].'</a>';[/syntax] and the link would lead to the page "player.php" and on that page my code would look something like [syntax=php]echo $_GET['player']; echo '<body>Stats</body>';[/syntax]
Re: Generate dynamic page based on link clicked.
I personally would set up the link like:
[syntax=php]echo "<a href=\"player.php?player={$row['players']}\">{$row['players']}</a>";[/syntax]
(Note the double quotes and backslashes)
You might also want to be careful with displaying content direct from the GET variable, anybody can just type in what they want including code. Think about cleaning it, there's a good PHP function here: http://tpa.im/jm
[syntax=php]echo "<a href=\"player.php?player={$row['players']}\">{$row['players']}</a>";[/syntax]
(Note the double quotes and backslashes)
You might also want to be careful with displaying content direct from the GET variable, anybody can just type in what they want including code. Think about cleaning it, there's a good PHP function here: http://tpa.im/jm
- killfrog47
- Posts: 106
- Joined: Tue Mar 12, 2013 2:52 am
- Location: Tempe, AZ
- Contact:
Re: Generate dynamic page based on link clicked.
Helx wrote:I personally would set up the link like:
[syntax=php]echo "<a href=\"player.php?player={$row['players']}\">{$row['players']}</a>";[/syntax]
(Note the double quotes and backslashes)
You might also want to be careful with displaying content direct from the GET variable, anybody can just type in what they want including code. Think about cleaning it, there's a good PHP function here: http://tpa.im/jm
Alright that is a good idea. I took a look at the function though i thought i understood what was going on i started to think how i would implement it. What would the $value be? Is that my $row['players']? Then I noticed this [syntax=php]$sample = "<a href='#'>test</a>";
$sample = clean($sample);
echo $sample;[/syntax]
That also confused me haha. Please forgive me im still new to PHP. Im taking classes in college next semester to learn php better but till then im dead in the water lol
WAIT! I figured it out! lol Idk why it took me so long but I got it. It makes sense now. I had a moment of slowness. I forgot how to use functions =P also question: Why would you use the \"stuff\" anyway?
Re: Generate dynamic page based on link clicked.
killfrog47 wrote:Why would you use the \"stuff\" anyway?
Well, I like to be able to put variables straight into the string, so instead of having to break the whole thing by doing:
[syntax=php]'something '. $var .' sdf';[/syntax]
I can just:
[syntax=php]"something {$var} sdf";[/syntax]
Which requires that double quotes are used, and because there are double quotes in the string (<a href=""> etc) PHP picks up on that and thinks you're ending the string. Rather than changing the string to accommodate it (eg. by using single quotes on the href: href='#'), it's easier to just tell PHP to ignore it by using a backslash before each conflicting character.
It also applies if you use single quotes:
[syntax=php]echo '<a href=\'lol\'>et cetera</a>';[/syntax]
TL;DR: It tells PHP that the double quotes in the string isn't code.
Hope it helps
- killfrog47
- Posts: 106
- Joined: Tue Mar 12, 2013 2:52 am
- Location: Tempe, AZ
- Contact:
Re: Generate dynamic page based on link clicked.
Helx wrote:killfrog47 wrote:Why would you use the \"stuff\" anyway?
Well, I like to be able to put variables straight into the string, so instead of having to break the whole thing by doing:
[syntax=php]'something '. $var .' sdf';[/syntax]
I can just:
[syntax=php]"something {$var} sdf";[/syntax]
Which requires that double quotes are used, and because there are double quotes in the string (<a href=""> etc) PHP picks up on that and thinks you're ending the string. Rather than changing the string to accommodate it (eg. by using single quotes on the href: href='#'), it's easier to just tell PHP to ignore it by using a backslash before each conflicting character.
It also applies if you use single quotes:
[syntax=php]echo '<a href=\'lol\'>et cetera</a>';[/syntax]
TL;DR: It tells PHP that the double quotes in the string isn't code.
Hope it helps
That does help alot! Now I have the pages being created and everything is working =) I am cleaning all variables before they get entered to the db and I set up DB permissions to read only. Thank you for all your help =)