Giter Site home page Giter Site logo

How to send a GET request? about mu HOT 5 CLOSED

Jahak avatar Jahak commented on May 22, 2024
How to send a GET request?

from mu.

Comments (5)

lastguest avatar lastguest commented on May 22, 2024

$_GET is used to retrieve parameters passed by the URL query string.
http://php.net/manual/it/reserved.variables.get.php

For instance, if you call your script with this request:

http://example.com/foo?username=bar

the $_GET['username'] variable is assigned to bar.

By the way, in your script you are redeclaring the GET / route 2 times, and you are not invoking the route dispatcher µ::_(); after the route definitions.

from mu.

Jahak avatar Jahak commented on May 22, 2024

@lastguest , added µ::_();
Please tell me how to get the user name using $ _GET using your PHP micro-router?

from mu.

Jahak avatar Jahak commented on May 22, 2024

write a simple example of the method $_GET

from mu.

lastguest avatar lastguest commented on May 22, 2024

Just try this :

µ::GET('/', function(){
    var_dump( $_GET );
});
µ::_();

Now you can call it in your browser like this :

http://localhost:8080/?name=hello+world&number=123

array(2) { ["name"]=> string(11) "hello world" ["number"]=> string(3) "123" }

Important:

• You must setup a front-controller pattern for redirecting all requests to the index.php file.
If you are using Apache you must define an .htaccess like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php

• Some web server configurations appends the query string part of the request URL to the $_SERVER['REQUEST_URI'] global, therefore breaking routing on parameters passing.
In these cases you must replace the REQUEST_URI text in µ class definition with REDIRECT_URL.

A more stable approach is replacing the getenv(REQUEST_URI) with strtok(getenv(REQUEST_URI),'?') in µ class definition.

Please, remember that this is an experiment just for fun. Do not use it in production!

from mu.

Jahak avatar Jahak commented on May 22, 2024

@lastguest , well, thank you

from mu.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.