View Full Version : Using $_GET
KingPuyol
02-06-2007, 11:52 AM
I want to know how to make those PHP links like:
index.php?page=hello
index.php?page=player&id=747
etc..
Someone please tell me how, and if there is another way other than $_GET, then please tell me.
I'm not a beginner, but teach me as a beginner please.
AN-net
02-06-2007, 03:43 PM
do you want to know how read it into the php file or how to make a link to a php file?
also you made a contradiction, you are beginner or you aren't. you can't be both, sry:(
harmor19
02-06-2007, 03:54 PM
I wrote this (http://xenweb.net/forums/showthread.php/your-own-subpages-61.html?t=61) I hope it helps.
KingPuyol
02-07-2007, 06:04 AM
also you made a contradiction, you are beginner or you aren't. you can't be both, sry:(
What I meant is I know how to do it but I make mistakes most of the time, so I said it's better teaching the easy way.
I wrote this (http://xenweb.net/forums/showthread.php/your-own-subpages-61.html?t=61) I hope it helps.
Thanks but can you also tell me how can I do the sub sub pages, like index.php?act=mods&do=download&modid=45
You got it, OK now teach me the HARD WAY!
And can you also tell me how can I use the CASE and ARRAY
Marco van Herwaarden
02-07-2007, 04:11 PM
And can you also tell me how can I use the CASE and ARRAY
See http://nl2.php.net/manual/en/control-structures.switch.php and http://nl2.php.net/manual/en/ref.array.php
KingPuyol
02-07-2007, 05:32 PM
Thanks Marco, but can anyone also tell me how can I do the sub sub pages, like index.php?act=mods&do=download&modid=45
__________________
One extra thing, what is "global $anything, $anothervar"
I read about it and it's:
An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.
So I wanted to know what's the use of it?
Marco van Herwaarden
02-07-2007, 05:47 PM
Just create if branches in your script:
KingPuyol
02-07-2007, 08:15 PM
Just create if branches in your script:
I didn't understand what you meant!
AN-net
02-08-2007, 01:37 AM
if($_REQUEST['modid'] == 46)
{
do something;
}
if($_REQUEST['page'] == "home)
{
do something else;
}
please though run your data through the vbulletin GPC if your using vbulletin or sanatize incoming data.
harmor19
02-08-2007, 02:48 AM
if($_GET['act'] == "mods")
{
echo "List mods";
if($_GET['do'] == "download")
{
echo "download mod ID: ".$_GET['modid'];
}
}
KingPuyol
02-08-2007, 06:16 AM
if($_GET['act'] == "mods")
{
echo "List mods";
if($_GET['do'] == "download")
{
echo "download mod ID: ".$_GET['modid'];
}
}
Thanks, I really appreciate it, and the "List mods" will be shown everywhere isn't it?
if($_REQUEST['modid'] == 46)
{
do something;
}
if($_REQUEST['page'] == "home)
{
do something else;
}
please though run your data through the vbulletin GPC if your using vbulletin or sanatize incoming data.
What's the difference between $_GET and $_REQUEST?
harmor19
02-08-2007, 06:23 AM
$_REQUEST can be used as both $_POST and $_GET
KingPuyol
02-08-2007, 09:27 AM
Thanks for the reply :)
Paul M
02-08-2007, 09:43 AM
Perhaps you should start by reading about php, these are pretty basic questions covered by any php online manual or book.
KingPuyol
02-11-2007, 09:21 AM
Perhaps you should start by reading about php, these are pretty basic questions covered by any php online manual or book.
I actually know these stuff but they didn't work at the first place for some typo mistakes, that's why I asked.
I just have one more question: :)
If I had a MySQL table called players:
ID - Player
1 - John
2 - Paul
3 - Puyol
By using $_GET, how can I set the value of "$playername" to the player name in the database according to the ID.
For example, if someone opened index.php like:
index.php?id=1, then I want the $playername to be set to John, and if ?id=2 then to be set to Paul, then if ?id=3 then to be set as Puyol. According to what's on the database.
ragtek
02-11-2007, 10:12 AM
Perhaps you should start by reading about php, these are pretty basic questions covered by any php online manual or book.
as paul says
start reading about php and mysql
or look into the tutorials
https://vborg.vbsupport.ru/forumdisplay.php?f=184
KingPuyol
02-11-2007, 03:01 PM
as paul says
start reading about php and mysql
or look into the tutorials
https://vborg.vbsupport.ru/forumdisplay.php?f=184
I know what he said and I couldn't find it because what I want to do is lots of combination of codes and I've read lots and lots of php tutorial and I can't waste some time in finding this answer, so if anyone can be kind enough in giving me the answer please. :)
RedTyger
02-11-2007, 04:55 PM
You would use something like
SELECT *
FROM yourdb
WHERE id='" . $_REQUEST['id'] . ''
In this case I'd also use strlen and is_numeric to check that it's only a number and it's very short character sequence being requested, or some other failsafing of your choice. Note the use of REQUEST and not GET, when using vBulletin you should always use REQUEST and not GET.
$_REQUEST can be used as both $_POST and $_GET
That's not strictly speaking true, $_REQUEST is a combination of both. It's not a case of "can be used" as you don't have a choice.
thincom2000
02-11-2007, 06:13 PM
I'm pretty sure you would want to clean the variables before doing something like that.
Guest190829
02-11-2007, 06:45 PM
I'm pretty sure you would want to clean the variables before doing something like that.
Yes, always clean global variables $_POST, $_GET, and $_REQUEST with vBulletin's built in cleanser:
https://vborg.vbsupport.ru/showthread.php?t=119372
RedTyger
02-11-2007, 08:16 PM
That's what I just said. :confused:
Is there any reason to use the input cleaner instead of just performing the checks yourself as I suggested? The advantage that way is that you don't have to change the way you access the variable and you can also assign extra or different checks instead of being limited to the few GPCs and can assign if/else to deal with the data as well. That's a terrific tutorial but the one thing it doesn't do is explain why you should use it instead of your own way.
KingPuyol
02-12-2007, 01:11 PM
Thanks :)
If I did this:
$playername = SELECT name FROM players WHERE id='" . $_REQUEST['id'] . ''
Will it work?
Guest190829
02-12-2007, 03:44 PM
That's what I just said. :confused:
Is there any reason to use the input cleaner instead of just performing the checks yourself as I suggested? The advantage that way is that you don't have to change the way you access the variable and you can also assign extra or different checks instead of being limited to the few GPCs and can assign if/else to deal with the data as well. That's a terrific tutorial but the one thing it doesn't do is explain why you should use it instead of your own way.
It complies with vBulletin's coding standards, I don't know why you wouldn't want to use a tool like that provided for you. If you are going to run the sanitizing functions manually, it is fine, but it is always open to you forgetting to clean a variable. If you use $vbulletin->GPC, you have more confidence that your variables are being cleansed properly.
Analogpoint
02-12-2007, 04:08 PM
The only case where I would consider not using vB's sanitizing functions would be if you're only dealing with one single int variable in a plugin, then it would probably be more readable/simpler to just use intval to force it to be an int. If I remember right, that's what vB does anyway to sanitize an int variable.
$i = intval ($_GET['i']);
In all other cases (and maybe even in this one), follow Danny's advice.
KingPuyol
02-13-2007, 12:24 PM
What should I put in the red text if I'm going to using REDTYGER's advice?
if($_GET['id'] == "here)
{
do something else;
}
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.