Search code examples
php.htaccesscurlgetplaceholder

Running .htaccess from php + $_GET friendly urls + cURL issue


I need to ask you how to run .htaccess from PHP because I'm making software, but I want to users can by languages setup their own names of links, but I can only do this in .htaccess, but in .htaccess I don't know how to get from PHP language and then use it to specify which patches will be existing. Also I want to make friendly URLs in PHP (from .php?id=0 to .php/id/0).

And the last... cURL.

I saw that in one software, how I can using cURL read page text (I have link my.ip.com/idk.php?id=3 and the id 3 from server will only say text "ok" and I want to get that text to PHP and use it)


Solution

  • 1) You cannot run .htaccess with anything. It's config file for your web server.

    2) Example of http://you.com/@username

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^@(.+)$ profile.php?username=$1 [L,QSA]
    

    then get $_GET["username"] in profile.php

    3) You should make your own .htaccess RewriteRule

    4) Small example about cURL.

    <?php
    $post = [
        'PostName' => 'PostValue'
    ];
    $ch = curl_init('http://www.example.com');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($ch);
    curl_close($ch);
    var_dump($response);
    ?>