FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Assigning a variable in PHP by address bar





ChrisCh
Hey there. I'm trying to assign a variable to something from an address bar. What I was thinking was something like this:
Code:
http://.../filename.php?msgid=3


So what I'd want to do is have a variable in filename.php called msgid, and make it equal what is typed in after it: in this case, 3.

If anyone knows how to do this, please reply Smile
hexkid
Code:
<?php //filename.php
echo "The variable value is ", $_GET['msgid'];
?>


[Edit]
Code:
<?php //filename.php
if (isset($_GET['msgid'])) {
    echo "The variable value is ", $_GET['msgid'], ".";
} else {
    echo "Variable not set.";
}
?>
kawkazEE
you can use $_GET...

example:

filename.php?id=1234

in my example the value(1234) will be stored in $_GET["id"], you can directly retrieve it or passed its value to a variable and call the value of the variable..

$pass_it_to_me = $_GET["id"]

this sure works... now to display the value be sure to check that the variable actually has been passed a value..

if (isset($pass_it_to_me)) {
echo $pass_it_to_me;
} else {
echo "No value passed.";
}

hope this helps...
ChrisCh
Wow thanks hexkid Smile I'll try it as soon as the server works again...

Thanks also for your help kawkazEE, but hexkid's code already used $_GET - just less complex Smile
Alias
you could use the $_GET method just like this,

Code:
<?php

/*
assigning a variable in
filename.php
*/

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~ E_NOTICE);

print "Hello ", {$_GET['msgid']};

?>
ChrisCh
Thanks guys for all your help! It's very much appreciated Smile

I've got it all working now Very Happy
manum
try this

<?php
$msgid=$_REQUEST['msgid'];
echo("$msgid");
?>
ChrisCh
Heya. Thanks for helping manum, but as I mentioned above, I've already got it all setup and working to my satisfaction Smile

Thanks for your input though Smile
santium
If register_globals is on, you can just use $id for something like index.php?id=245, $id will be 245. However, I'm not sure if register_globals is on or off here.
Related topics
PHP Question
Fire Fox address bar small icon
Icons in address bar
address bar image
Fields appearing in URL address bar
Logo in the address bar ?
storing current page address as php variable
Need Help, how to transfer to files to server using $_GET
How to make Global Variables with PHP?
how to display icon in the the address bar of browser
Javascript, writing code in the address bar without clearing
Delete Data from the Address Bar (Fire Fox and Explorer)
colouring the address bar
Yahoo Search Results from Address Bar of Firefox Searches
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.