...

View Full Version : function why isnt this working?



kimboslice
03-24-2010, 01:56 PM
why isnt this working? when i run the script i get a blank page



<?php
function useragent () {
$useragent = $_SERVER['HTTP_USER_AGENT'];

echo "$useragent";
}
?>

Rowsdower!
03-24-2010, 02:02 PM
You don't need quotes around $useragent when echoing. Get rid of those quotes and if your page is still blank try running print_r($_SERVER); and see what turns up.

kimboslice
03-24-2010, 02:13 PM
thanks, it doesnt work when i remove the quotes either. shouldnt it work?

how would i put print r in the function?

Rowsdower!
03-24-2010, 02:15 PM
<?php
function useragent () {
$useragent = $_SERVER['HTTP_USER_AGENT'];

//echo "$useragent";
print_r($_SERVER);
}
?>

That should spit out the entire array of data in $_SERVER. Run that and check to see if 'HTTP_USER_AGENT' is actually set to anything.


EDIT: Oh, duh! You haven't called your function yet. You have only declared it. Try this instead:

<?php
function useragent () {
$useragent = $_SERVER['HTTP_USER_AGENT'];

echo $useragent;
}
useragent ();
?>
Always try the simplest things first... :D

MattF
03-24-2010, 02:19 PM
You have to call the function for it to run.



<?php
function useragent () {
$useragent = $_SERVER['HTTP_USER_AGENT'];

echo "$useragent";
}

useragent();
?>


Edit: Bugger, beaten to it. :D

Rowsdower!
03-24-2010, 02:20 PM
You have to call the function for it to run.



<?php
function useragent () {
$useragent = $_SERVER['HTTP_USER_AGENT'];

echo "$useragent";
}

useragent();
?>


Edit: Bugger, beaten to it. :D

Yes, but not by far. It's early (here at least) so I'm chalking it up to that!

kimboslice
03-24-2010, 02:23 PM
yeah that probably will help thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum