$url = $_GET['url'];
echo $url;
i dont know why i get a Undefined index error
You have to provide ?url= in the address bar. If that is missing, you get the index error. You can change it to this:
$url = isset($_GET['url']) ? $_GET['url'] : '<no url set>';
echo $url;
hi thanks for the help, it has cleared the errors but its not echoing out the url ? ive been following a php tutorial and i dont how he has got it working
my index.php
<?php
$url = isset($_GET['url']) ? $_GET['url']: '<no url set>';
echo $url;
require 'controllers/' .$url . '.php';
$controller = new $url;
?>
my controller :
<?php
class Index {
function __construct() {
echo 'we are in index';
}
}
?>
Thanks it works now
is there anything wrong with my code ?
Warning: require(C:\wamp\www\mvc\controllers) [function.require]: failed to open stream: Permission denied in C:\wamp\www\mvc\index.php on line 7
What did you do? Pasting an error without showing your code is kinda useless.
oh i i did not do nothing i just went to my index.php,
which has the require statement
( ! ) Notice: Undefined index: url in C:\wamp\www\mvc\index.php on line 3
Call Stack
# Time Memory Function Location
1 0.0007 364448 {main}( ) ..\index.php:0
( ! ) Warning: require(C:\wamp\www\mvc\controllers) [function.require]: failed to open stream: Permission denied in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0007 364448 {main}( ) ..\index.php:0
( ! ) Fatal error: require() [function.require]: Failed opening required 'controllers/' (include_path='.;C:\php\pear') in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0007 364448 {main}( ) ..\index.php:0
Show your code, not the call stack. Although the last error says the file does not exist, so you need to check that before you include it.
its the same code i showed you at the start here is :
index.php
<?php
$url = $_GET["url"];
echo $url;
require 'controllers/' .$url;
$controller = new $url;
?>
index.php in the folder called controller:
<?php
class Index {
function __construct() {
echo 'we are in index';
}
}
?>
that is all i have
If there is no url specified, the require will fail, that is why you have those messages. You will have to call it as I specified earlier, or add error checking.
heres my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?
i do specify index.php
http://localhost:8080/mvc/index.php?url=Index
it echos out index
and these error messages
( ! ) Warning: require(controllers/Index) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0005 365256 {main}( ) ..\index.php:0
( ! ) Fatal error: require() [function.require]: Failed opening required 'controllers/Index' (include_path='.;C:\php\pear') in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0005 365256 {main}( ) ..\index.php:0
The problem may be:
require 'controllers/' .$url; // this should open controllers/index.php
$controller = new $url; // this should be Index (the class name)
The following could help:
require 'controllers/' . strtolower($url) . '.php';
$controller = new $url;
If you want to open index.php?url=Index
that works now i appreciate your help
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.