Jump to content

Simple issue


amam

Recommended Posts

Hello,

 

I don't have any php knowledge and am having a hard time trying to implement the following:

 

- a drupal node is getting a numeric parameter with the URL in the following form "http://the.url/?X=123"

- what I want is for the script to check if the value has been passed with the URL, then use it in a form... if the entered URL was "http://the.url" without the X variable, then use a default value of 321.

 

<?php $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?>

 

Thanks in advance for your help.

Link to comment
Share on other sites

Thank you pagegen, I did imagine that there's something really simple with this sting of code, but you defenitely saved me a lot of time.

 

Can anyone advise if using such code is safe, or should the value be checked if it's actually an integer first?

Link to comment
Share on other sites

I usuly use

mysql_escape_string($_GET['']);

to add slashes

 

but there are lots of ways to make string safe

 

you will need

 

is_numeric($X);

 

so u can try

 

if(is_numeric($X)){

echo "its a number";

} else {

echo "not a number";

}

 

I think safty is allways 1st so yes validation is allways a good thing

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.