1

How do I send requests to multiple directory structures to one page? For example, how would I send requests to somesite.com/users/new and requests to somesite.com/users/delete to somesite.com/users/index.php so that the index.php page can see what the original url was. I need to do this without redirects. I know this is very easily possible because tons of php frameworks and CMSes have that feature. (Wordpress, Codeigiter, TinyMVC, just to name a few.)

I am programming in PHP.

Thanks in advance.

yskywalker
  • 95
  • 1
  • 1
  • 7
  • I think this question might have been answered [here](http://stackoverflow.com/questions/2126762/url-rewriting-in-php-without-htaccess). – yskywalker Jul 20 '12 at 01:19

1 Answers1

1

You would probably require some AJAX to perform asynchronous get requests to retrieve data from /users/delete and /users/new from index.php

You could use JQuery plugin (http://jquery.com/) to make AJAX calls simpler as well

This is an example of a javascript that uses JQuery $.get() which makes an asynchronous get requesst

<html>
<head>

...import jquery javascript plugin...

<script>

//executes init() function on page load
$(init);

function init(){
   //binds click event handlers on buttons where id = new and delete
   // click function exectutes createUser or deleteUser depending on the 
      button that has been clicked

   $('#new').click(function(){createUser();});
   $('#delete').click(function(){deleteUser();});
}

function createUser(){

   //submits a get request to users/new and alerts the data returned
   $.get('users/new',function(data){alert('user is created : '+data)});
}

function deleteUser(){
   //submits a get request to users/delete and alerts the data returned
   $.get('users/delete',function(data){alert('user is deleted : '+data)});
}

</script>

</head>

<body>

<input id='new' type='button' />
<input id='delete' type='button' />

</body>
</html>
Wee Kiat
  • 1,208
  • 1
  • 10
  • 12