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");
Related
Let me explain my need with simple example.
I have folder called "Website" Inside that some sub folders and files.
Website(Main-Folder)
pages(sub-folder)
(files)
page1.php
page2.php
target_page(sub-folder)
(file)
target.php
menu(sub-folder)
(file)
menu.php
index.php (this file is in main folder)
This is my sample folder view, I just included menu.php(navigation menu with links)file in my both pages and index.php file.
In menu.php i have a nav link to target.php page
So, to
access target.php file in
index page mean i have to use Target
Target
access target.php file inside
the pages folder mean i have to use
Target
Is there any short way to access that target page, because I don't like to create multiple menu.php file and set the different location for same file.
Sorry for bad English, Thanks.
[UPDATED]
The best alternative is to define your root path once and for all !
We use another file that we could call whenever we need the PATH. Like for example in settings.php that we save near index.php:
define('My_ROOT' , 'http://'.$_SERVER['HTTP_HOST'].'/');
Then whenever needed, we require that file and so we could write links like follwing :
Target
P.S: Please notice that in my first Answer I used the file path and that could be used for relative inclusion not Frontend links !
Just put your href starting with "/" :
link
Is it possible to change https://example.com/ab12 to https://example.com/ but showing content from https://example.com/ab12 by editing .htaccess as a part of AB testing?
You could put the content of "ab12" inside of the index.html file and then it will automatically redirect to that page.
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
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.
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.