RustyNox
RustyNox

Reputation: 469

Get an activation key string from URI

I have a URL in this format:

https://www.example.com/activate/9ajebaidblahdeblahblah2020

My setup is /activate/index.php

How can I parse /9ajebaidblahdeblahblah2020 with the index.php file in the /activate folder?

I have tried...

$current_url = $_SERVER['REQUEST_URI'];
echo $current_url;

//OR

var_dump($_SERVER['REQUEST_URI']);

What I would like to do is (purpose)...

$current_url = explode("/", $_SERVER['REQUEST_URI']);
//echo $current_url[2];

Thank you ahead of time for any help.

Upvotes: 1

Views: 195

Answers (3)

nice_dev
nice_dev

Reputation: 17805

Add a .htaccess file in your activate project folder with the below code:

RewriteEngine On

RewriteRule ^/?activate/(.+)$ /activate/index.php?val=$1 [NC,L,P]

Demo: https://htaccess.madewithlove.be?share=aa64900e-ba78-4f17-9369-326f4384dd47

Later in your index.php file, you can just use as:

<?php

echo $_GET['val'];

Upvotes: 2

FaAzI Ahamed
FaAzI Ahamed

Reputation: 61

<php

$url = $_SERVER['REQUEST_URI'];

$route_path = parse_url($url, PHP_URL_PATH);

$segments = array_filter(explode("/", $route_path));

print_r($segments);

You'll get the following Result,

Array( [1] => activate, [2] => 9ajebaidblahdeblahblah2020 )

Upvotes: 0

zvi
zvi

Reputation: 4746

You don’t have a page named 9ajebaidblahdeblahblah2020 on your server.

You can redirect all URL’s to index.php with htaccess (https://httpd.apache.org/docs/current/howto/htaccess.html).

See more details here: Redirect all to index.php using htaccess

Upvotes: 1

Related Questions