How do I check in php to see if a URL variable is present?

I want to check to see if a URL variable is present or not.

This doesn't work. I thought <> '' would be enough to check if 'x' variable is present or not. it is giving me an UNEXPECTED T-VARIABLE error. I think there should be a step earlier checking to see if X variable is there at all before checking its value, correct? (on some of my links, x variable is not present and on some it is.

if $_GET['x'] <> '';
$x_coordinate = $_GET['x'];
else $x_coordinate = 0.0;
<?php
$name = $_GET['name']."/thumbs/"; //"'".$_GET['name']."/thumbs/'";   //stores the URL variable into a variable that php can use
$filedir = $_GET['file'];
$nameonly = $_GET['name'];
 
if $_GET['x'] <> '';
$x_coordinate = $_GET['x'];
else $x_coordinate = 0.0;
if $_GET['y'] <> '';
$y_coordinate = $_GET['y'];
else $y_coordinate = 0.0;
if 
$zoom = $_GET['zm'] <> '';
else $zoom = 25;
//echo $name , $file
?>

Open in new window

polaatxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Try:

<?php
$name = $_GET['name']."/thumbs/"; //"'".$_GET['name']."/thumbs/'";   //stores the URL variable into a variable that php can use
$filedir = $_GET['file'];
$nameonly = $_GET['name'];
 
if (isset($_GET['x']) && $_GET['x'] != '')
{
	$x_coordinate = $_GET['x'];
}
else
{
	$x_coordinate = 0.0;
}
 
if( isset($_GET['y']) && $_GET['y'] != '')
{
	$y_coordinate = $_GET['y'];
}
else
{
	$y_coordinate = 0.0;
}
 
if (isset($_GET['zm']) && $_GET['zm'] != '')
{
	$zoom = $_GET['zm']
}
else
{
	$zoom = 25;
}
//echo $name , $file
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ee_rleeCommented:
hi

 i think you missed the if statement for this.

if
$zoom = $_GET['zm'] <> '';
else $zoom = 25;

0
polaatxAuthor Commented:
Hi hielo: did you write all the  {  signs  by hand and position them so neatly or is there a program that does this for you?
0
hieloCommented:
By hand. It's fun :)
Rumor has it that there are programs out there, but I wouldn't know which ones they are.
0
polaatxAuthor Commented:
thank you. More than what I expected.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.