I'm making a page as follows, There will be a menu for on the left. In the menu there will be links home, page1, page2, page3 and pageProtected. When I click on any page, this menu will remain unchanged. Only the content of the page on the right will change.
I made a file "left.php" and content of each page as "page1Content.php" etc.
When I click on page1, it takes me to page1.php, which includes left.php and page1Content.php.
Html code...
<?php include("left.php")?>
more html code...
<?php include("page1Content.php")?>
So in each file, only the second included file changes. All the html code are identical for all pages. But I have a protected page, which needs a login window. It is called "pageProtected.php". The thing is I want to keep this file in the main folder, but keep the content: "pageProtectedContent.php" in a folder where I put the .htaccess file.
However when I do this, it doesn't ask password. And when I put "pageProtected.php" in this folder, I have to change "left.php" that I include in this file. Then my purpose of keeping a unique "left.php" is not satisfied. What are my options?
Probably this is a very novice question, but I couldn't find a solution in the internet. Note: I don't want to use frames for the left menu.
.htaccess files only prevent the files from being accessed in a web browser, PHP can include files in htaccess protected folders as if they weren't protected.
I think what you need to do is have pageProtectedContent.php check for a cookie or use php sessions to facilitate login and authentication.
If it is included and the user is not logged in, it will display a login form, if they are logged in, then it will display the protected content.
The only other way to use .htaccess would be to put the protected pages in the protected folder, but you would then need to change your include statements to use ../left.php etc.
Related
My Header navigation menu links are malfunctioning...
My project folder has 2-3 sub-folders. One of them is the "INCS" folder, which carry some files like the "HEADER.php","FOOTER.php" e.t.c. Another sub-folder "USER": Which is the folder that contains every file that that does processes on the user. For example the "USER" folder has the "WELCOME.php", "INDEX.php" files in it, which is where the user is redirected to after successful Login.
In the "WELCOME.php" file for example i included the "HEADER.php" file from the "INCS" sub-folder in this manner "../incs/header.php".
<div class="probootstrap-loader"></div>
<?php include '../incs/header.php'; ?>
<!-- END: header -->
I expect that on the "WELCOME.php" page, when the user clicks on the "NAVIGATION LINKS" it should be like this structure "root/link.php" and that it should take the user to the "LINK" page, but when i hover on any of the links i get this structure "root/user/link.php".
Considering the fact that these other links are in the ROOT DIRECTORY not the SUB-FOLDERS..
I really hope someone understands this, because its the first time i am experiencing this issue and i don't know how best to explain it
I am trying to create a php website on WordPress for the first time.
When I create a page, it creates a permalink which is of the form http://localhost/?p=123. I don't know if there is a corresponding file.
I've installed insert-php plugin to read php code. It works fine on a static page. But how do I include another php file? I want to include my_utilities which contains all the back-end functions, in login. It has a permalink 'http://localhost/?page_id=45'.
What to do?
include 'http://localhost/?page_id=45' doesn't work.
Pages you define in WordPress's backend are pages mostly setup for your users to view / read. They, by default, have this URL structure of http://localhost/?p=123 (though this can be changed, but that's a whole different lesson).
To include a script file, upload the file to your folder structure where you have your website then refer to it in your include statement as follows:
include('path/to/folder/my_script.php');
EDIT: You may also want to have a look into WordPress Page Templates:
Pages are one of WordPress's built-in Post Types. You'll probably want most of your website Pages to look about the same. Sometimes, though, you may need a specific Page, or a group of Pages, to display or behave differently. This is easily accomplished with Page Templates.
For exapmle your wordpress file is at
/var/www/html/wp-content/myphpfiles/test.php
To include the test.php file in your wordpress page you have to following.
[insert_php] include('wp-content/myphpfiles/test.php'); [/insert_php]
Thats it.
My first post here...I hope that I don't brake any rules and if I do please go easy on me :-)
I have a page a.php with a simple form with one field: name
User puts his/her name and submits. File b.php is in the action field of the form and so it gets the form.
b.php needs to load a slideshow depending on the user input. Let's say there is a folder "clients" and it has folders John and Mary. Each of these folders will have an index file and other sub folders of images, CSS, JS, etc. The index files have relative paths to the subfolders like: ./images/pic1.jpg ./display.css etc.
Here is my problem:
I want to load, say John/index.html without changing the URL that would be xyz.com/b.php
If I use an iFrame the source code will show that xyz.com/clients/John/index.html is loaded and if I use PHP include("xyz.com/clients/John/index.html") then the relative paths that are in the John/index.html won't work.
I am trying to hide the physical location of the slideshow so I can always serve them under the same URL as far as the user can see. Changing relative paths to absolute won't work because that will give away everything that I am trying to hide!
I have simplified the form, folder name, etc. to explain the problem. Could anybody suggest any solutions please.
I don't fully understand the question but <base> may help. It tells the browser to make all links from a page relative to another URL instead of where the page was loaded from
<base href="http://mydomain.com/mybaseurl/" />
I'm loading my files using read file so it seems like there are like 5 pages on the index page, and arguments index the url specify what will show.
So for example, my profile site http://profile.campatet.com has 3 pages:
login page
profile page
search page.
If the url is http://profile.campatet.com/?s=something, it will load search.php into the index page and you will see a search page.
If it's http://profile.campatet.com/?user=something, it will load profile.php into the index page and it will be a user profile.
If it's just http://profile.campatet.com/, it will load login.php into the index page and it will be the login page.
Now, the my profile page is loaded into the index page when the index page uses the readfile() function. However, the my profile page needs to check a cookie to make sure the person who is accessing the my profile page actually is the account owner.
However, the page can't find the cookie when it is loaded through the readfile function for some reason. It works properly when I open it as a independent file, so I know there is nothing wrong with my code for the self profile page.
Why is this happening?
Use include or its variants require, require_once etc. instead of readfile()
Let's say I have a simple CSS layout and my menu is a column on the side. This menu is going to be on every web page (About 10 web pages). If I have items on this menu in the form of links and such, how can I make it so that if I add a link on one page, it will add it to all pages? Would you just make it a PHP page and in that <div> element include a PHP file called menu or something, and just edit that PHP file (so I only have to edit that file and not every web page)?
If this is raw PHP (no frameworks) then you simply include it.
include('sidebar.php');
Make sure that you can access the file from where you are including it though. If you have files in a folder called foo for example, and accessed via example.com/foo/somefile.php you will have to change the include statement to include('../sidebar.php'); assuming sidebar.php is in the root.
As stated above, and include would do.
Drop this on every page you want your menu to appear:
<?php include("/yourMenu.php"); ?>
Just save the menu code as yourMenu.php and put it in the root and you are good to go.
i've used this trick before and it works well. you can use this in conjunction with an include php
Intelligent Navigation
If you are using the Apache web server it's even more simple and faster to use server side include (ssi). You can do the same for the footer and other common areas of your pages.
Here is the reference page: http://httpd.apache.org/docs/2.2/howto/ssi.html