Page 1 of 1

address bar variables[SOLVED]

Posted: Sat May 12, 2007 4:22 pm
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.

Posted: Sat May 12, 2007 4:45 pm
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

Posted: Sat May 12, 2007 5:01 pm
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

Posted: Sat May 12, 2007 5:22 pm
by eyespark

Code: Select all

<?php
function hello($var){
echo $var;
}
$var = $_GET['something'];
hello($var); 
?>

Posted: Sat May 12, 2007 5:32 pm
by kcpaige89
Thanx alot.