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.
address bar variables[SOLVED]
Moderator: General Moderators
address bar variables[SOLVED]
Last edited by kcpaige89 on Sat May 12, 2007 5:33 pm, edited 1 time in total.
You need to use the predefined variable $_GET. Here is an example:
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
Code: Select all
<?php
echo 'Hello! My name is '.$_GET['name'].'.';
?>More info -
http://us.php.net/manual/en/reserved.va ... iables.get
http://www.w3schools.com/php/php_get.asp
would i need to change my function:
to look like that?
http://www.mydomain.com/index.php?something=Hello_World
Expected output
Hello_World
Code: Select all
<?php
//index.php
function hello($_GET['something']){
$hello = $_GET['something'];
echo $hello;}
hello();
?>http://www.mydomain.com/index.php?something=Hello_World
Expected output
Hello_World
Code: Select all
<?php
function hello($var){
echo $var;
}
$var = $_GET['something'];
hello($var);
?>