Jump to content

CSS and javascript disappeared


jrws

Recommended Posts

Hey guys,

I have recently stumbled across this, I understand how to use mod_rewrite and I am happy, however:

When I use the new shorter url I have no styling or javascript. Although the link to the style sheet and javascript show, neither work. What do I do?

Here is the header file:

<?php
require_once ('libary/config.php');
require_once ('libary/functions.php');
//Header
session_start();
ob_start();
error_reporting(1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title><?= $title . '---' . $siteName; ?></title>
<link rel="stylesheet" type="text/css" href="./libary/default.css">
<script type = "text/javascript" src="./libary/main.js"></script>
</head>
<body>
<?

if (isset($_COOKIE['username']) && isset($_COOKIE['u_level']) && isset($_COOKIE['u_id']) &&
    isset($_COOKIE['password']))
{
    //$id = $_COOKIE['u_id'];
    $sql = "SELECT username AND password FROM user WHERE username = '{$_COOKIE['username']}'AND  password ='{$_COOKIE['password']}'";
    $result = mysql_query($sql) or die(mysql_error());
    //$row = mysql_fetch_array($result);
    if (mysql_num_rows($result) == 1)
        //If the username and password combination exist set the sessions

    {
        $_SESSION['username'] = $_COOKIE['username'];
        $_SESSION['u_level'] = $_COOKIE['u_level'];
        $_SESSION['u_id'] = $_COOKIE['u_id'];
        $_SESSION['password'] = 1;
        //echo 'Success';
    } else
    {
       header('Location: '.$siteURL.'logout.php');
   exit();
    }
}
if (isset($_SESSION['username']) && $_SESSION['password'] == 1 && $_SESSION['u_level'] ==
    6)
{
?><div class="holder">
<div id="header">

|<a href="<?= $siteURL; ?>">Home</a>|
<a href="<? $siteURL; ?>new_news.php">Post news</a>|
<a href="<? $siteURL; ?>view_news.php">View all the news</a>|
<a href="<? $siteURL; ?>admin.php">Admin page</a>|
<a href="<? $siteURL; ?>profile.php?id=<?= $_SESSION['u_id']; ?>">Your profile</a>|
<a href="<? $siteURL; ?>profile.php">All profiles</a>|
<a href="<?= $siteURL; ?>logout.php" onClick="return verify('Are you sure you want to logout?')" >Logout</a>|
</div>

<?
} elseif (isset($_SESSION['username']) && $_SESSION['password'] == 1)
{ ?>
<div class="holder">
<div id="header">
|<a href="<?= $siteURL; ?>">Home</a>|
<a href="<?= $siteURL; ?>new_news.php">Post news</a>|
<a href="<?= $siteURL; ?>view_news.php">View all the news</a>|
<a href="<?= $siteURL; ?>profile.php?id=<?= $_SESSION['u_id']; ?>">Your profile</a>|
<a href="<?= $siteURL; ?>profile.php">All profiles</a>|
<a href="<?= $siteURL; ?>logout.php" onClick="return verify('Are you sure you want to logout?')">Logout</a>|

</div><?
} else
{
?>
<div class="holder">
<div id="header">
|<a href="<?= $siteURL; ?>">Home</a>|
<a href="<?= $siteURL; ?>login.php">Login</a>|
<a href="<?= $siteURL; ?>register.php">Register</a>|
<a href="<?= $siteURL; ?>view_news.php">View all the news</a>|

</div>

<?
}
?>

Here is the .htaccess:

#.htaccess
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^news/?$ view_news.php [NC,L] # Handle news requests
RewriteRule ^news/([0-9]+)/?$ view_news.php?=$1 [NC,L] # Handle news requests

Note that the first one includes the style sheet and css, the second one doesn't.

BTW here is the output from the second one:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>News---Doonside Technology High</title>
<link rel="stylesheet" type="text/css" href="./libary/default.css">
<script type = "text/javascript" src="./libary/main.js"></script>
</head>
<body>
<div class="holder">
<div id="header">
|<a href="http://localhost/school%20site/">Home</a>|
<a href="http://localhost/school%20site/login.php">Login</a>|
<a href="http://localhost/school%20site/register.php">Register</a>|

<a href="http://localhost/school%20site/view_news.php">View all the news</a>|

</div>

<b>Test</b><br />Test<br /><a href="?id=1">View this post</a><br/><br><b>TEst</b><br />Test<br /><a href="?id=2">View this post</a><br/><br> [<b>1</b>] <div id="footer">
19 April 2009 6:07:48 PM<br><small>Powered By Kardaina Entertainment©</small></div>

</div>
</body>
</html>

Please help, and thanks for your time;

-James-

I have noticed, that if I change the url to http://localhost/school%20site/news/

The css and javascript exist.

I also noticed that when I click on links from that page the link is something like this:

http://localhost/school%20site//news/news

If you're using rewrites, if your links are relative, the client pc is going to be looking in them relative to the current directory. And since this directory is virtual, the actual css/js file probably does not exist.

 

For example, if your current virtual directory is http://www.yourdomain.com/something/something-else, it's going to look for your css file in http://www.yourdomain.com/something/something-else/css.css which obviously does not exist.

 

If you give your css file an absolute reference, liike http://www.yourdomain.com/css.css, it will always look for it in that place.

Thanks for clearing that up,

I have tried that, however now the rewrite wont work, I get a 404, the only thing I changed was the absolute as you suggested, I have not edited the .htaccess file. So I am stuck, and I have no idea as to why this would happen.

But thank you, hopefully the bloody thing will work again.

-James-

It is on local host, however I will upload onto a free website if you like.

Once it's uploaded it will be on

www.sandstorm.net46.net

EDIT:

When I tested it on the website everything seemed to be working ok, so why isn't it working on localhost....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.