So I have developed a website with the main page named as home.php. I have also got a domain name and hosting from Godaddy. What I want to know is that how do i tell my site to display the home.php as the homepage?
I want that when the user goes to example.com -- home.php should be presented, and not example.com/home.php.
thanks.
just rename your home.php to index.php
Name the file index.php and it will work
You're options:
Rename you're file to index.php
Rename you're file to default.php
Do a iFrame
Do a php redirect: header("Location: home.php");
You could do a .htaccess redirect: DirectoryIndex home.php
I would choose #1 or #2!
If you choose to do an iFrame you would have to "break out" to enable the back button in the browser.
If you choose to do a redirect with php you will waste server resources.
.htaccess way: ...Don't know what's bad.
you can:
rename home.php to index.php
create index.php with content
<?php header('Location: home.php');?>
But, I don't recommend option #2 as it generate another useless HTTP request.
Related
I want to change home URL of my project. I have a project in localhost/locoff. when I hit this localhost/locoff url it open my Index.php file, but I want to open my login.php file after hiting this localhost/locoff url. how it is possible?
Please help me for this
You can add header location on index.php file to redirect it to login.php.
Ex. in index.php:
<?php
header("location:login.php");
I have a wordpress installation that is located in the root folder: mydomain.com
This website has a blog that is directed to mydomain.com/blog
What I would like to achieve is to redirect all traffic that goes to mydomain.com/blog to another wordpress installation that has a blog and located on a temporary domain on my server - server.myserverdomain.com/~seconsite/blog
I would like to also keep the main website domain mydomain.com/blog
Thanks !
Redirect by PHP
header("Location: server.myserverdomain.com/~seconsite/blog");
die();
Redirect by HTML
Method 1 :
<meta http-equiv="refresh" content="0; url=http://server.myserverdomain.com/~seconsite/blog/" />
Method 2 :
<script>window.top.location = 'http://server.myserverdomain.com/~seconsite/blog';</script>
What you can do is
Redirection by JavaScript
Make one file named index.html, in which put html,head and body tags and also put javascript code as below
<script>
window.location="http://UrlToRedirect";
</script>
Put this index.html file into your /www/blog directory or whichever directory you have for mydomain.com/blog.
And make sure you don't have any other file named as index in that directory except this one which you will prepare.
And you are good to go.
I have three pages on my localhost 1 is my index page,2 is my universal header page which is under includes folder of and 3 is my html file which is under html folder.The header file is included in both the index file and html file like that...
for index.php-include("includes/header.php");
for html.php-include("../includes/header.php");
and my header has the link of index.php page that is (./index.php)
Now my questions is that when i open my index page and click on link of index page from my header it takes me to same index.php page but when in open html.php page and then click index.php page link from header it does not go to index.php page but it goes to this page-
(localhost/educational%20website/html/index.php) how to solve that.
And i also want to know that write now i am on localhost but when i make my site live is there any need to change the paths because i am making around 150 pages with your technique plaese so please answer me that kind of technique that is used for both localhost and on live
Your are including paths relatively, use a (absolute) base path in your index.php to fix this:
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/header.php');
One way is to define a variable or a constant for the site's url in the header.php file. Then in all your other pages, you could just use this variable/constant when you need to mention the other urls.
Eg(put this as first line in your header.php file):
define('SITE_URL', 'http://localhost/educationalwebsite');
Here, we have defined a constant named SITE_URL. Then in other pages, you are already including this header file. Isn't it? So, this constant will be available in your index.php, html.php and other pages.
And suppose for a link in your html.php file(to point to the index.php), you could use it like this:
Home
If you want to include link to the html.php file residing inside html folder, it would be like:
HTML
By using this way, if you are uploading the whole site to a live server, you only need to change one line, ie. the first line in header.php, where we have defined the SITE_URL constant. Just change it's value to the new URL of the home directory of your website.
Hope this helps
So I'm trying to make a theme from my Html file. And using require('file.php') where file.php is a series of different components of my theme. Now when I access the file directly, I still see the html. How do I make it display a blank page when user accesses the file.php directly?
Explanation
So let's say I make index.php and I want to include the header file(header.php)
When I require('header.php'), everything works perfect. Now when I try to access the header.php, I can see the html content of it. How to I make this appear blank instead of seeing the header.php piece?
Thanks
In that case, If you want to execute header.php inside the index.php or etc. You need to add or define a flag in parent files (wherever you want header.php to be executed or simply adding in to the common file which is called in all parent files), In header.php file you need check the defined flag is set or has some value. If it is not set, then stop execution by using die(); function.
In index.php,
<?php $HeaderAllow ='1'; ?>
In header file,
<?php
if($HeaderAllow=='' or !isset($HeaderAllow)){
die();
}
?>
you can use $_SERVER['SCRIPT_FILENAME'] here to check and then make page blank in header.php.
<?php
if($_SERVER['SCRIPT_FILENAME'] == 'header.php') {
exit();
}
Putting the include files in a seperate folder and protectinng with .htaccess is good idea.
Same issue here.
deny direct access to a folder and file by htaccess
The easiest way is to put your includes in a directory and deny access to that directory in your .htaccess file
I'm having problems with PHP sessions dropping data and redirecting back to my login page.
This is the directory structure I have from the top:
Login // Contains files to login/logout
Main // Contains pages for logged in users
index.php // Login screen with fully operational form
In login directory: check_login.php
In main directory: page1.php, folder1 and folder2
In folder 1: home.php, include1.php
In folder 2: include2.php
(Sorry if this is not very easy to understand)
This is the code I run when logging in on check_login.php:
session_start();
$_SESSION["id"] = $id;
header("location:../main/page1.php"); //into main directory
All of the pages contain the same styling (heading, navigation, footer) and have one main content block that changes per page so therefore I use includes contained in folder1 and folder2 depending on the content to be displayed. By default, home.php is included for the home page which is located in folder1. Other pages use includes such as include1.php or include2.php which could be from either folder.
At the top of page1.php:
session_start();
if($_SESSION["id"] == '')
{
header("location:../index.php");
}
From page1.php, if I navigate to a page with an include that is located in folder1, this works fine. If I navigate back to the home, an include also in folder1 this works fine. Both times I can read the id variable from session.
However if I navigate to a page with an include located in folder2 I get redirected to my login page.
Any ideas?
You need to always include your session start. A good approach for this would be to create a header.php or bootstrap.php or similar that you can include_once at the beginning of each file that extends that relies on the session. Then your code is going to cleaner and easier to manage, in addition to working properly.
I have resolved this, and cannot believe my idiocy.
In one of the includes where I was echoing a link to another page, this was wrong and in fact pointing to my login page all along. Everything is working fine now, appreciate for all the help. Typical schoolboy error.