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-

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.