-4

I want to get the value of the VARIABLE_PARAMETER, if someone opens the following link: www.example.com/VARIABLE_PARAMETER in PHP instead of making GET request's to make a dynamic webpage using PHP. Kindly explain the procedure, if possible.

Hariom
  • 13
  • 3

3 Answers3

1

There is no way to make a browser request a URL in that format from a form submission naturally. You have to apply program logic to it.

You've tagged this PHP so a server side solution would be to examine the requested URL with that and then issue a redirect.

<?php
    # form_action.php
    if (isset($_GET['get'])) {
        sanity_check_value_of($_GET['get']);
        header("Location: http://www.example.com/" . urlencode($_GET['get']);
        exit;
    }

You could also achieve this with a URL rewriting tool such as mod_rewrite or URL rewrite.

It is also possible to handle this client side using JavaScript (by capturing the submit event on the form, preventing the default behaviour, generating the new URL and assigning it to location) but the speed benefits over doing it server side probably aren't enough to justify the extra work (and you shouldn't do it without the server side alternative).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

You can achieve this with a mod_rewrite rule in a .htaccess file.

Create a htaccess file with the following content:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9\-\/]+)$ index.php?url=$1

When you request the page with domain/test (is the same as domain/index.php?url=test), you can access it in the $_GET variable ($_GET["url"]).

-1

Use Post request method rather than Get request method. For tutorial please refer W3schoolsTutorial Form Handling

Jayyi Q
  • 54
  • 2
  • Using a POST request wouldn't work, that would make the `` portion entirely hidden instead of moving it from the query string to the path. – Quentin Dec 29 '15 at 12:11