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:
Any more questions or do you have it down pat?
It's not all that difficult
If you had something like:
player.php?player=test1&foo=1&what=loljkyou could access it all in code like so:
<?php echo $_GET['player']; // Displays "test1" echo $_GET['foo']; // Displays "1" echo $_GET['what']; // Displays "loljk" ?>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.
That helps out alot actually! So my link on my website could look something like thisHelx wrote:Hi.
It's not all that difficult
If you had something like:
player.php?player=test1&foo=1&what=loljkyou could access it all in code like so:
<?php echo $_GET['player']; // Displays "test1" echo $_GET['foo']; // Displays "1" echo $_GET['what']; // Displays "loljk" ?>Just like that!
Any more questions or do you have it down pat?
echo '<a href="player.php?player='.$row['players'].'">'.$row['players'].'</a>';and the link would lead to the page "player.php" and on that page my code would look something like
echo $_GET['player']; echo '<body>Stats</body>';
Re: Generate dynamic page based on link clicked.
I personally would set up the link like:
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
echo "<a href=\"player.php?player={$row['players']}\">{$row['players']}</a>";(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.
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 thisHelx wrote:I personally would set up the link like:
echo "<a href=\"player.php?player={$row['players']}\">{$row['players']}</a>";(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
$sample = "<a href='#'>test</a>"; $sample = clean($sample); echo $sample;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.
Well, I like to be able to put variables straight into the string, so instead of having to break the whole thing by doing:killfrog47 wrote:Why would you use the \"stuff\" anyway?
'something '. $var .' sdf';I can just:
"something {$var} sdf";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:
echo '<a href=\'lol\'>et cetera</a>';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.
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 =)Helx wrote:Well, I like to be able to put variables straight into the string, so instead of having to break the whole thing by doing:killfrog47 wrote:Why would you use the \"stuff\" anyway?
'something '. $var .' sdf';I can just:
"something {$var} sdf";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:echo '<a href=\'lol\'>et cetera</a>';TL;DR: It tells PHP that the double quotes in the string isn't code.
Hope it helps