LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-25-2005, 09:50 PM   #1
cb8100
LQ Newbie
 
Registered: Feb 2004
Location: Monterey, CA USA
Distribution: Slackware
Posts: 20

Rep: Reputation: 0
PHP URL Arguments


I'm just learning PHP and trying to figure out how to accept URL arguments (if that's even the right term). So, if this is the URL (to the file on my web server)

http://mysite.com/my_page.php?type=1&page=2

How would I rertreive the arguments after the question mark? I plan on passing the arguments to a MySQL database to generate dymanic pages.

I've googled this for hours with no luck.
 
Old 03-25-2005, 10:40 PM   #2
tisource
Member
 
Registered: Feb 2002
Posts: 322

Rep: Reputation: 30
This is really more of a PHP question than a linux question, however...

Variables in PHP depend on the way in which it was submitted (GET, POST or PUT). If you are passing some variables via your URL, it is a GET request.

In recent versions of PHP, these values are available in the global $_GET array variable. In older versions (pre-3.x), you use $HTTP_GET_VARS.

For example, using the following URL:
http://mysite.com/my_page.php?type=1&page=2

You would get to your variables 'type' and 'page' this way:

$_GET["type"] and $_GET["page"]

If it was submitted via a POST request, you'd get to your variables like this:
$_POST["type"] and $_POST["page"]

Using your URL, $_GET["type"] would equal '1' and $_GET["page"] would equal '2'.

Check this page for more info:
http://us2.php.net/reserved.variables

Also, you may want to check PHP Builder (www.phpbuilder.com/board/), as it is specific to PHP related questions.

Hope that helps.

Last edited by tisource; 03-25-2005 at 11:47 PM.
 
Old 03-26-2005, 02:39 AM   #3
cb8100
LQ Newbie
 
Registered: Feb 2004
Location: Monterey, CA USA
Distribution: Slackware
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks for the advice. Works perfectly



And, for the record:
"This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game."
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php mysql variable arguments in query. ldp Linux - Software 0 10-26-2004 07:56 AM
Arguments in PHP function declaration Parksy Programming 5 07-04-2004 04:22 PM
How to pass arguments from $prompt for php script ukjairaj Linux - Software 4 06-25-2004 11:14 AM
php not taking arguments when passed through URLs BrianK Linux - Software 2 03-29-2004 11:38 AM
PHP arguments and virtual includes nodger Linux - Networking 1 01-19-2004 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration