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. Link to comment https://forums.phpfreaks.com/topic/219808-simple-issue/ 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" ?> Link to comment https://forums.phpfreaks.com/topic/219808-simple-issue/#findComment-1139479 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? Link to comment https://forums.phpfreaks.com/topic/219808-simple-issue/#findComment-1139486 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 Link to comment https://forums.phpfreaks.com/topic/219808-simple-issue/#findComment-1139487 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! Link to comment https://forums.phpfreaks.com/topic/219808-simple-issue/#findComment-1139489 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() Link to comment https://forums.phpfreaks.com/topic/219808-simple-issue/#findComment-1139543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.