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 Link to comment https://forums.phpfreaks.com/topic/296572-change-a-variable-from-its-url/ Share on other sites More sharing options...
fastsol Posted May 31, 2015 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']; 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. 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
Archived
This topic is now archived and is closed to further replies.