473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to pass variables via GET

4
Hello I have been wondering How do web developers do this "index.php?option=..." the url has a question mark at the end and some function?!? Do you have any links for tutorials that can guide me in learning this?!?
May 22 '07 #1
6 2545
Is the GET method.
You have the chance to use 2 methods:

GET: the var value is passed directly in the URL after a ?

POST: the var is invisible in the URL (used exspecially with passwords...)

You can chose the method in the form adding the method propriety and then adding ='GET' or ='POST'
PHP sintax to get vars in GET is:
$a=$GET_['nameoftheform']
PHP sintax to get vars in POST is:
$a=$POST_['nameoftheform']

Kind Regards
May 22 '07 #2
Atli
5,058 Expert 4TB
This is called the HTTP GET protocol.
It is used to transfer data between pages, but being a pretty old protocol, it has limitations, such as length restrictions (due to URL length restrictions) aswell as character restrictions. (# and other special characers are not available using GET)

You can add GET variable on any URL by adding a ? sing at the end of the URL. Then you can add variables formatted like this "varName=varValue". To add more than one you can seperate them usint a & sign.
Example: index.php?var1=value1&text=Thisistext1

Now you could access those variables in PHP using the $_GET array
Example using the URL in the previous example.
Expand|Select|Wrap|Line Numbers
  1. print $_GET['var1']; //Outputs: value1
  2. print $_GET['text']; //Outputs: Thisistext1
  3.  
You can also access this data usint the $_REQUEST array. This array is different however. It does not only contain GET data. It also containts POST and COOKIE data. Depending on your PHP settings, identical variables in the other protocols might override your GET values.

Here are some examples of how GET values can be set.
Expand|Select|Wrap|Line Numbers
  1. // This link will refresh the page and change the
  2. // GET variable text
  3. echo "<a href='?text=fromalink'>Linkage</a>";
  4.  
  5. // This form will post its text field as the
  6. // GET variable text
  7. ?>
  8. <form action="?" method="GET">
  9.   Text: <input type="text" name="text" />
  10. <br /> <input type="submit" text="Submit" />
  11. </form>
  12. <?php
  13.  
  14.  
May 22 '07 #3
tensai
4
I see so that's how it is... I will try this method then... Thanks... If I have more questions regarding this I will just post it here then... Thank You!

P.S

How would I use the GET method to link to another page?!? for example I have an index.php file and a test.php file.... in my index.php file there should be a link to open the test.php file... How will I use the GET method in order for it to link to the test.php file?!?? In order for me to have a "www.example.com/index.php?page=title"
May 23 '07 #4
pbmods
5,821 Expert 4TB
Changed thread topic to better match contents.
May 23 '07 #5
ak1dnar
1,584 Expert 1GB
Index.php
[PHP]
<?php
echo '<a href="header.php?page=test1">Page 1</a>';
echo '<br>';
echo '<a href="header.php?page=test2">Page 2</a>';
?>[/PHP]

header.php

[PHP]<?php
$link = $_GET['page'];
header('Location:'.$link.'.php');
?>[/PHP]

put these two files with another two files named test1.php and test2.php with the same dir and execute index.php
May 23 '07 #6
tensai
4
Thank You for the reply... I will try this then.
May 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: adolf garlic | last post by:
Suggestions please for strategy to share values across app. Scenario: I have an asp.net app that uses some com components along with .net classes. Configuration settings for various things...
10
by: tshad | last post by:
I want to access multiple arguments based on name passed. For example I have the following asp:textboxes: BillingAddress1 BillingAddress2 BillingCity ShippingAddress1 ShippingAddress2...
7
by: Gladen Blackshield | last post by:
Hello All! Still very new to PHP and I was wondering about the easiest and simplest way to go about doing something for a project I am working on. I would simply like advice on what I'm asking...
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
13
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
17
by: Daniel | last post by:
When I use the CreateThread API method, what do I need to do when I want to pass more than one parameter where LPVOID lpParameter is passed? Daniel
21
by: raylopez99 | last post by:
In the otherwise excellent book C# 3.0 in a Nutshell by Albahari et al. (3rd edition) (highly recommended--it's packed with information, and is a desktop reference book) the following statement is...
1
by: kkshansid | last post by:
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file srt.php <script type="text/javascript"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.