...

View Full Version : Good way to use subfolders?



doodguy
05-08-2009, 09:15 PM
I'm creating mysite.com and all works fine. Now I'm making admin stuff so its mysite.com/admin/ and having errors with the sessions working on pages within /admin and also links I have to define as ../linkname.php/html can anyone give me a pointer as to whats up plsss?

hthought
05-08-2009, 11:45 PM
What you say is not that clear and i cannot really help. Could you explain a bit better what the problem is? From what i hear i suppose that it may be a urls rewrite problem probably.

bazz
05-09-2009, 01:18 AM
I guess you are asking about making your links work when the file using them is inside a different directory/folder, from the ones which do work.

Well, while I do not understand the link ../linkname.php/html I think you may benefit from the following:

Links should be locally global IMV. That means they are going to work no matter the site structure and they are not relative to the url/domain.

so I usually use /folder/filename.php/params. The is a link that goes from the root directory

folder/filename.php/params takes you to the sub-folder of the folder containing the file.

for your sessions issue, you'll need to post the code so we can see why it works in the root dirs but not in the admin dir.

bazz

doodguy
05-12-2009, 04:38 PM
Hey bazz. General code I'm using for starting pages is as follows:


<?PHP session_start();
ini_set("session.gc_maxlifetime", "180000");
?>

Then underneath that I type my code. So basically if you think about file structure I want the main site to be mysite.com/ and whatever pages there. Then, I want a mysite.com/admin so that way all my admin pages and stuff I code can be in mysite.com/admin/.....php

So overall I have a simple mysql database. In the database it has a users table with an admin field set to value of y or n defaulted to n.

When user logs in if they have the admin y then the header has an include code to include a header with admin links. Then admins can click around those links, and do different admin stuff. Here is code to include admin links from my header.php.


<?



include("db.inc.php");
$id_user=$_SESSION['id_user'];

$check=mysql_query("select * from users where id_user='$id_user'");
$result =mysql_fetch_array($check);
$admin=$result['admin'];

if ($admin=='y')
{
Echo "<TABLE border=40 cellspacing=0 cellpadding=0 width=100% bgcolor=#E6F3FF>
<tr>
<td align=middle class=navText>USER ID: " . $id_user . "<BR><A href=/messageoftheday.php>Message of The Day</A> Reserved for future use</td>
</tr>
</TABLE>";
}
?>

doodguy
05-12-2009, 04:42 PM
Oh let me state how site is laid out basically. . .


I have a header which displays my banner, and possibly admin links. I do an include statement on every page to include the header.

Then I have the main body of the page usually setup as such:


<HTML>
<TABLE>
<TR>
<TD>
<TABLE>
<TR>
<TD>Include loggedinlinks.html here</TD>
</TR>
</TABLE>
</TD>
<TD>
<TABLE>
<TR>
<TD>Main stuff for current page your on goes here</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</HTML>



Pardon me if my coding convention sucks, I'm no pro, just doing this for fun, and learning.

bazz
05-12-2009, 04:46 PM
OK, I was trying to help with the links issue you were having. I am unable to assist with your sessions trouble because I have never used them in php.

as for your coding convention...yup, it seems wrong because you are using tables for layout. You said you were doing this for fun and learning so it would be better to start with semantic code now rather than learning two different ways, when the first is wrong and therefore a waste of your time.

bazz

doodguy
05-12-2009, 04:55 PM
bazz, if I shouldn't be using tables for my layout, what should I be using? Templates? Templates are done in CSS, which end up as tables anyways, right?

Len Whistler
05-12-2009, 06:28 PM
bazz, if I shouldn't be using tables for my layout, what should I be using? Templates? Templates are done in CSS, which end up as tables anyways, right?

Use divisions. Tables are good for tabular data - such as database output - if the data is easier to read or input with the tab key.






--------

doodguy
05-12-2009, 07:22 PM
cool. I'll look into divisions.

In the meantime, how do I enable sessions to work back and forth between /admin and root folder? Is it possible?

Len Whistler
05-12-2009, 09:06 PM
cool. I'll look into divisions.

In the meantime, how do I enable sessions to work back and forth between /admin and root folder? Is it possible?

Yes ..... Also to link between folders use ../ Example:

home/admin
home/includes

The db_connect.php is in the includes folder, but you also would like to use it from within the admin folder. The link would be:

"../includes/db_connect.php"


--



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum