amam Posted November 25, 2010 Share Posted November 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
pagegen Posted November 25, 2010 Share Posted November 25, 2010 <?php $X = $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?> Quote Link to comment Share on other sites More sharing options...
amam Posted November 25, 2010 Author Share Posted November 25, 2010 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? Quote Link to comment Share on other sites More sharing options...
pagegen Posted November 25, 2010 Share Posted November 25, 2010 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 Quote Link to comment Share on other sites More sharing options...
amam Posted November 25, 2010 Author Share Posted November 25, 2010 Thank you mate, you've been a great help. Got it working, and got a little bit of new knowledge! Quote Link to comment Share on other sites More sharing options...
pagegen Posted November 25, 2010 Share Posted November 25, 2010 These sites might help u also mate http://www.w3schools.com/php/default.asp http://php.net/manual/en/ -- < I mostly use that to learn php built in functions i.e. is_numeric() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.