didz666 Posted May 31, 2015 Share Posted May 31, 2015 Im still learning how to use php so sorry if this is a stupid question. Is it possible to change a variable in a php using its url when calling it using ajax. <?php $variable = '1'; //can i change it via the url to 2 ?> <script> $.ajax({ type: 'POST', url: "http://mysite.co.uk/myphp.php?$variable=1", success: function (data){ $("$mydiv").html(data); } }); </script> any help would really be apreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/296572-change-a-variable-from-its-url/ Share on other sites More sharing options...
Solution fastsol Posted May 31, 2015 Solution Share Posted May 31, 2015 Yes, for url variables you use the $_GET superglobal. $variable = $_GET['your_url_var_name']; // If the value is supposed to be a integer only, this is best for security $variable = (int)$_GET['you_url_var_name']; Quote Link to comment https://forums.phpfreaks.com/topic/296572-change-a-variable-from-its-url/#findComment-1512929 Share on other sites More sharing options...
didz666 Posted May 31, 2015 Author Share Posted May 31, 2015 Hi fastsol thats great thanks very much, I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/296572-change-a-variable-from-its-url/#findComment-1512931 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.