address bar variables[SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kcpaige89
Forum Newbie
Posts: 6
Joined: Sat May 12, 2007 4:13 pm

address bar variables[SOLVED]

Post by kcpaige89 »

I'm trying to figure out how functions get information from the address bar, such as when I registered for this forum the web link was posting.php?mode=register&agreed=true .

I have built a simple function to try and replicate that, to an extent, but idk how to do it.

i type in, http://www.mydomain.com/index.php?hello=bob

<?php
//index.php
function hello($hello){
echo $hello;}
hello();
?>

expected output:

bob.

I've tried several variations on both the web address and the coding, i'm just not sure how it works.
I'm trying to do this with javascript, and if there is a way to do it with AJAX (idk any but some have told me that would be a way to do it) i'd be glad to know. Thank you in advance.
Last edited by kcpaige89 on Sat May 12, 2007 5:33 pm, edited 1 time in total.
The Bat
Forum Newbie
Posts: 14
Joined: Thu Feb 01, 2007 3:57 pm

Post by The Bat »

You need to use the predefined variable $_GET. Here is an example:

Code: Select all

<?php
echo 'Hello! My name is '.$_GET['name'].'.';
?>
Now type in yourwebsite.com?name=Andrew and the page will display "Hello! My name is Andrew.".

More info -
http://us.php.net/manual/en/reserved.va ... iables.get
http://www.w3schools.com/php/php_get.asp
kcpaige89
Forum Newbie
Posts: 6
Joined: Sat May 12, 2007 4:13 pm

Post by kcpaige89 »

would i need to change my function:

Code: Select all

<?php
//index.php
function hello($_GET['something']){
$hello = $_GET['something'];
echo $hello;}
hello();
?>
to look like that?

http://www.mydomain.com/index.php?something=Hello_World

Expected output

Hello_World
eyespark
Forum Commoner
Posts: 50
Joined: Tue Jan 24, 2006 7:36 am

Post by eyespark »

Code: Select all

<?php
function hello($var){
echo $var;
}
$var = $_GET['something'];
hello($var); 
?>
kcpaige89
Forum Newbie
Posts: 6
Joined: Sat May 12, 2007 4:13 pm

Post by kcpaige89 »

Thanx alot.
Post Reply