user162098
user162098

Reputation: 1

Getting an error for $_server['SCRIPT_NAME']

I am trying to get path of page via

<?php

/**
* @author 
* @copyright 2013
*/

$current_file = $_SERVER["SCRIPT_NAME"];
echo $current_file;


?>

It gives an error Notice: Undefined index: SCRIPT_NAME

Also I included it in my login page code

<form action="<?php echo $current_file;?>" method="POST">
Username : <input type="text" name="username"/> Password : <input type="password" name="password" />
<input type="submit" value="LogIn" />
</form>

It also gives an error regarding $current_file

Upvotes: 0

Views: 2442

Answers (1)

xkeshav
xkeshav

Reputation: 54016

from php Manual

Under Windows 2000, running IIS and PHP 4.3.10, $_SERVER['SCRIPT_NAME'] is not available, however $_SERVER['SCRIPT_FILENAME'] is present and seems to contain the same information

also one more theory

$_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME'] may not always be set correctly. Some web hosts implement php as a CGI in such a way that they can turn it on or off for each virtual domain. Several $_SERVER and $_ENV variable values may be incorrect for documents in subdirectory subdomains of these virtual domains. other way to get Current FILE name

<?php
if (!isset($_SERVER['DOCUMENT_ROOT']))
    $_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['SCRIPT_FILENAME'], 0, -strlen($_SERVER['SCRIPT_NAME']));
?>

Upvotes: 7

Related Questions