Mateo
Mateo

Reputation: 69

Getting 'GET or POST' from url

I am setting up a 404 page but i need it to get the value from the address. What i mean is, if the URL is localhost/main?var=0, I want to get the number which is in the URL. So 0 because in the URL it says var=0. I have tried using $_GET['var'].

Note, The directory main does not exist, because i am using a 404 page to get the information.

Upvotes: 1

Views: 84

Answers (3)

Mateo
Mateo

Reputation: 69

In the end i used $_SERVER['REDIRECT_QUERY_STRING'] and explode to get the id.

$get  = $_SERVER['REDIRECT_QUERY_STRING'];
$videoID = explode("v=", $get);
echo $videoID[1];

Upvotes: 0

Jan
Jan

Reputation: 43169

If I understand you correctly, you want to catch all parameters even if the called script/page whatsoever does not exist. In order to get this to work with Apache you could set up an error handler in your .htaccess file.

RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.php

You will then be able to read your variables in 404.php in the following arrays:

$_SERVER['REDIRECT_REQUEST_METHOD'] # POST
$_SERVER['REQUEST_METHOD'] # GET

Is this what you tried to achieve in the first place?

Upvotes: 1

Eva Lauren Kelly
Eva Lauren Kelly

Reputation: 413

You could try $_REQUEST['Var']. However, I tend to use lower-case variables.

Upvotes: 0

Related Questions