This is the hierarchy of my folder and files:
/website
/admin
/about
editAbout.php
adminHeader.php
adminDashboard.php
adminLogout.php
adminHeader.php is the header of my pages, so it is being included in all pages. It also contains the Logout link that has this code:
Logout
In adminDashboard.php page it works, but in editAbout.php page, it didn't work because the link is not right, it becomes
http://www.domainname.com/admin/about/adminLogout.php
I tried to change the link to
<a href="http://www.domainname.com/admin/adminLogout.php">
and also by using the $_SERVER['DOCUMENT_ROOT'] but didn't work also.
Does anyone know how to reset the link to the right one?
you can use ../ to come back to the parent folder
it becomes enter code hereLogout
Try this:
$_SERVER['SERVER_NAME'] . "/admin/adminLogout.php";
The SERVER_NAME value refers to the domain.
You do not need to add the server name, as the browser will put that in for you. So just make all of your paths absolute (from the web browser's point of view):
/admin/adminLogout.php
Example:
<a href="/admin/adminLogout.php">
Related
So, I have a question regarding paths in links. Here's the problem: In my assignment all my links are broken (not all but half of them don't work).
html_start.php includes nav.php and start_html is included in /admin/index.php and so on.
public_html
html_start
nav
styles.css
admin
index.php
user
index.php
index.php
First I've tried using absolute path eg. a href = "/user/index.php" but the assistent warned me that it leads to homepage of my university not my index.php.
If I use relative links, half of them work do to the includes.
Sadly all of these work in my environment but not when it's uploaded to my school so I don't know how it will behave until I upload the assignment and I have only one attempt to correct it.
Now, i use include in almost every page - eg. include( __DIR__.'/app.cfg.php') and that apparently works.
So my question is can I do the same with links? I've read somewhere that it doesn't do the same thing.
Looks like you're working in "root" (localhost?), where absolute links are fine, but when the site gets set up at your school's server, then absolute links point to the school's domain instead of the subdirectory where your project is.
What you need is using <base> tag in combination with relative links. Note that it may mess up your css/js/images, so you'd need to update all paths to be relative (not starting with /). Here's an example:
<html>
<head>
<base href="http://example.com/"/>
[...]
link
The link above would point to http://example.com/dir/page.html. Basically, setting an URL in base tag sets what is the "root" of your website, and all relative links will respect it. You can store the value of base in your site's config and echo it in the template, so when your site is set up on another server you'd update the config file and all links/images/css/etc would work.
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
The problem I got, is that I can't go up a directory to open an ajaxpage.
Here is the link to the directory above:
<img src="../images/buttons/community.png" alt="Community" />
This won't work. What have I done wrong?
Javascript paths are relative to the page being displayed. Assuming you're viewing a page in the pages directory, you're actually requesting pages/pages/community.php.
Use community.php as your URL or use an absolute path.
I am making a site and I need to get the "root" directory of the site. Like if the filestructure was similar to
CloudShop
\-internal
\-js
...
\-inc
inc.all.php
index.php
\-login
login.php
loginError.php
page.php
In inc.all.php I am getting all the pages in the database so I can display them in the navigation bar and I am setting the links like <a href="page.php?id=XXX>PAGE_TITLE</a> However, when I click on one of the page links from login.php, it takes me to /CloudShop/login/page.php?id=XXX. I want it to take me to /CloudShop/page.php?id=XXX.
You can use path-absolute URIs. Suppose you had at http://www.example.com/shop/login/login.php:
page
The resolved URI would be http://www.example.com/shop/page.php?id=1.
Suggestion: Try the PHP Magic constants:
__DIR__
please,I am trying to create link to a php file in sub folder using tag but when I am testing the link it gives "NOT FOUND" error this is the code About
Make sure that name of file or folder is correct with caps lock text. something like this in below:
About
If about.php is in pages folder and you are gonna link to another file in this folder, you must remove ../ from the code, something like this:
About
Please provide link of About.php that we'll check it out, it's easy way to find the problem.
Browse to the file in the browser manually, then work backwards.
Draw a map of your directories, for visual aid
For example;
.public_html/
..pages/
page1.html
..files/
...config/
..folder1
..folder2/
index.html
The link from index.html to pages/page1.html would be
Page1
The link from pages/page1.html to index.html would be
Index