Jump to content

Change a variable from its url


didz666
Go to solution Solved by fastsol,

Recommended Posts

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
Share on other sites

  • Solution

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
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.