I am currently working in a application like wordpress. i need a php class to handle the url request for eg : if u load the below url in browser
http://somename.com/myaboutpage/
the handler should load the file about-us.php from my theme folder
and if i use the below url
http://somename.com/action/login/
the handler should trigger the file login-action.php from my application core and return the values
how its possible..
i tried to study how elgg & wordpress handle the request. but i am unable to get the exact..
so please help me.
Note the pages i create will be dynamic so i need a page handler fully dynimic like word press permalink handler
Have you set a BASE_URL in an index.php file? if you have, you could check to see if that is set, if it isn't it means the user has somehow managed to navigate directly to your about-us.php file. So something like
if(!defined('BASE_URL'))
{
require('/*your index.php file*/');
header('Location: BASE_URL')
exit;
}
Related
I am looking to use some php pages I created as a template across multiple subdomain websites. I want to change minor things across each subdomain (what database is being used and some basic settings but this is not important). I do not want to copy over all files every time I want to create a new subdomain as this will be a pain when making updates. So I want to be able to push updates to my "live" site that acts as a template for all other sites.
This is my current testing layout
I have a "live" site that looks something like this:
-dashboard
-division
-division->lookup
Each of these directories have an index.php that I want included when the appropriate url is visited.
For each subdomain website, I currently have:
-.htaccess file
-errors (includes 404.php)
Within my .htaccess file, I have the 404 page as this 404.php page and that page looks like this:
if((#include "/var/www/live".$_SERVER['REQUEST_URI']."/index.php") === false){
echo "DOES NOT EXIST";}
If the url you are trying to go to exists in "live" it includes it and it basically mirrors it.
This seems to work except for when I try a url that is more than 1 directory deep. For example, if I am trying to go to test.myurl.com/division/lookup I get Google's 404 page (This test.myurl.com page can’t be found).
I am feeling like there has to be an easier way to do this and I am doing this all wrong. Where can I look to do this better? Any tips?
This will check if the file exists and should address the depth issue
<?php
$filename = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
if (is_file($filename)) {
// file exists as requested
require_once $filename;
exit;
}
http_response_code(404); // may be unnecessary
?>
<!doctype html> ... <!-- 404 page content -->
Iam new to codeigniter framework and xampp server.Iam getting object not found error
when i click on fivespecies it is displaying error message
The welcome.php controller is your default, and when you don't declare a function name within the controller, it loads the index() function, so loading http://localhost/antimalarial/ loads the index function in your welcome controller.
However, if you want to load any other function within the welcome controller, you will need to provide the controller name AND the function name.
Your link should be http://localhost/antimalarial/welcome/fivespecies
Your might need to write your URL as: http://localhost/antimalarial/Welcome/fivespecies
If this link does not work, try this:
http://localhost/antimalarial/index.php/Welcome/fivespecies
This case is valid if you haven't already set the .htaccess file.
If you want to remove index.php from your url. Please download and add .htaccess file in your root directory. Click here to download the file.
Hope this helps.
I'm designing a website but I know if the user enters a wrong character into my url, a not found page will open for him . and I know it can be a way to hack my website. What should I do for that? for example if the user enters a ' into my url like this:
http://example.com/article.php?id=585'
He move to a not found page which I have designed it or move to the first page or the last page he was in.
Thanks.
You have to take 2 things into consideration:
Handling non-existent files
Handling non-existent article ids
Here's how to handle each case:
1) Create an .htaccess file and place it in your website root folder:
RewriteEngine on
ErrorDocument 404 /error.php # change this to your own 404 file path
2) Open the articles.php file and add this to the top (right after checking if your ID exists)
if(!valid_id($id)) {
//if you have php 5.3- use this
header('HTTP/1.1 404 Not Found');
//if you have php 5.4+ use this
//http_response_code(404);
include('error.php'); //change this path to your own 404 file
die();
}
Obviously, valid_id() is just a function example.
You will have to create a custom 404 page. So when your website doesn't get that page, it will show your custom page.
Try this link for custom page.
By the way from id=585'(apostophe after 585), I mean you want to prevent sql injection. Right? Just sanitise the input, that is, check if id is valid for not. You can find a lot of tutorial for that, just google it.
P.S : Believe me, It would take a lot more then a 404 Page to hack your server
just use this:
Open the articles.php file and add this to the top (right after checking if your ID exists)
if(!valid_id($id)) {
header('location:error.php'); exit();//change this path to your own 404 file
}
valid_id() is just a checking function example.
I'm not able to figure this out on my own so here I am asking for your help.
How do I load a website that I already made as a view in the code igniter default controller?
I put my website under a folder name site, and in the default controller I loaded the view site/index , but then in my site there are problems with the includes and redirects... I don't know why, I guess the way the site usually works with redirecting isn't compatible with code igniter style
edit: I guess I would have to turn off CI engine for this site, but I don't know why, because I would still need codeingiter to manage other parts of my application
"CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:
$route['default_controller'] = 'Blog';
Where Blog is the name of the controller class you want used. If you now load your main index.php file without specifying any URI segments you'll see your Hello World message by default."
http://codeigniter.com/user_guide/general/controllers.html
fragment copied from that link , you should put the controllers classname in that config, not the view
I guess it's better to choose one of these options:
Modify the existing site to a CodeIgniter site.
Keep your site separate from the CodeIgniter site, and just link between the two sites.
The way you are trying to do it seems very useless and causing a lot of extra trouble.
You can simply use the redirect function in your controller. If you supply a full URL you can go to any other page. You will, of course, leave your CI app.
redirect('http://www.example.net/page_in_external_site/');
Try using the APPPATH constant when defining the paths for the includes.
I know it's an old question, but you can try using a view template with an iframe, and you can pass the URL to the src property of the iframe. That way you can display your site inside a view, but still can't get access to the vars passed to the view from your site.
In system/Core/Loader.php change the line 141 to look like this:
$this->_ci_view_paths = array(APPPATH . 'views/' => TRUE, FCPATH => TRUE);
and to get the view is simple:
$this->load->view('application/ PATH_TO_VIEW');
In my indexAction() I want to redirect to a php file which is located in public folder named login.php.Now When I run this project as giving the url http://example.com:8881/index, it executes.In indexAction I have specified as $form_object = new Application_Form_Login().This form has a submit button and when submit button is clicked,in indexAction() I have specified as
if($form_object->isValid($login_data))
{
$this->_helper->redirector->gotoUrlAndExit('/public/login.php');
}
Because I want to redirect to login.php which is located in public folder.But when I click on submit url changes from http://example.com:8881/index to http://example.com:8881/public/login.php and says an error as Invalid controller specified (public) .I know why this error has occured because in url zend treats the public as controller which is not there.Now this checking should be disabled by the zend so that we can call that php file otherwise in url after the localhost everything will be treated as controller/action.What to do now for above stated requirement?Should I place the login.php file in other folder?What else has to be done?
Please suggest me.Its very much needed.Thanks in advance.
/public/ should never appear in your URLs. Sounds like you simply want to redirect to /login.php:
$this->_helper->redirector->gotoUrlAndExit('/login.php');
If this doesn't work please edit your question to include the contents of your .htaccess file.