vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Using $_GET (https://vborg.vbsupport.ru/showthread.php?t=138601)

KingPuyol 02-06-2007 11:52 AM

Using $_GET
 
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 I hope it helps.

KingPuyol 02-07-2007 06:04 AM

Quote:

Originally Posted by AN-net (Post 1176056)
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.

Quote:

Originally Posted by harmor19 (Post 1176063)
I wrote this 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

Quote:

Originally Posted by KingPuyol (Post 1176591)
And can you also tell me how can I use the CASE and ARRAY

See http://nl2.php.net/manual/en/control...res.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

Quote:

Originally Posted by Marco van Herwaarden (Post 1176934)
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

PHP Code:

if($_GET['act'] == "mods")
{
   echo 
"List mods";

   if(
$_GET['do'] == "download")
   {
       echo 
"download mod ID: ".$_GET['modid'];
   }



KingPuyol 02-08-2007 06:16 AM

Quote:

Originally Posted by harmor19 (Post 1177235)
PHP Code:

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?

Quote:

Originally Posted by AN-net (Post 1177217)
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

Quote:

Originally Posted by Paul M (Post 1177427)
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:
Code:

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

Quote:

Originally Posted by Paul M (Post 1177427)
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

Quote:

Originally Posted by ragtek (Post 1179794)
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

Code:

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.

Quote:

Originally Posted by harmor19 (Post 1177334)
$_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

Quote:

Originally Posted by thincom2000 (Post 1180065)
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

Quote:

Originally Posted by RedTyger (Post 1180150)
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?

Code:

if($_GET['id'] == "here)
{
do something else;
}



All times are GMT. The time now is 02:47 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01404 seconds
  • Memory Usage 1,783KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (2)bbcode_php_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (25)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete