Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

odinsride

macrumors 65816
Original poster
Apr 11, 2007
1,149
3
Hi all, first post in this subforum.

I am trying to get back into PHP/CSS/etc, and having a little problem with something - on my web hosting, my CSS is not working at all, however when I access my site locally through Xampp, it shows up fine. Any ideas what could cause this? Here's the code:

header.php
HTML:
<html>
  <head>
    <title>Sound Void</title>
	<link rel="stylesheet" type="text/css"  href="css/formatting.css" />
  </head>
  
  <body>

    <div id="header"><?php
					   include("title.html");
					 ?></div>
    <div id="divider"><?php include("topnav.html"); ?></div>
	<div id="content">

index.php
PHP:
<?php 
session_start();
header("Cache-control: private");
include ("header.php");
include ("db.php");

$count = 0;
$sql = "SELECT news_id, headline, text, date_posted, user_name FROM music_news";
$result=mysql_query($sql);
$rows=mysql_numrows($result);
mysql_close();

$i=0;

while($i < $rows) {
    	$id = mysql_result($result,$i,"news_id");
	$headline = mysql_result($result,$i,"headline");
	$text = mysql_result($result,$i,"text");
	$date = mysql_result($result,$i,"date_posted");
	$user = mysql_result($result,$i,"user_name");
    
	if ($count > 0){
		echo '<hr />';
	}

	echo '<h2>' . $headline . '</h2>';
	echo '<div id=newstext>';
	echo $text . '</div>';
	echo '<h5>Posted by ' . $user . ', ' . $date;
	if ($_SESSION['group'] == 1){
		echo ' || <a href=edit_news.php?id=' . $id . '>Edit</a>';
	}
	if ($_SESSION['group'] == 2 && $_SESSION['dbuser'] == $user){
		echo ' || <a href=edit_news.php?id=' . $id . '>Edit</a>';
	}
	if ($_SESSION['group'] == 1){
		echo ' || <a href=delete.php?id=' . $id . '>Delete</a>';
	}
	echo '</h5>';


	$count = $count+1;
	$i++;
  }
include ("menus.php");
include ("footer.php");
?>

As you can see, the index.php calls the header file with an include. The other stuff from the header file shows fine. The page displays everything it should other than the formatting.


Also, while I'm here, what does everyone here use for editing PHP/html on a mac? I was working with Vim last night but it doesn't seem to have color coding, which I prefer for writing code. Suggestions?
 
If it works locally but on when hosted, it's likely an issue with the path to the css file. The request for the css ("css/formatting.css") is probably not being resolved to the location you expect. Try using a path relative to your header.php.

I get syntax color with vim and gvim, but then I've been using the same .gvimrc and .vimrc files for years, copying from machine to machine, and I don't really know what's different between my rc files and the defaults.

Actually, I just remembered. Try typing ":syntax on" when you're editing. You can add that to .vimrc
and .gvimrc. I prefer gvim, by the way. Edit: I've uploaded my .gvimrc and .vimrc if you want to take a look. Copy gvimrc.txt to your home directory as .gvimrc and vimrc.txt as .vimrc (backup your own copies first, if you have them)

I've also used TextWrangler, which has syntax highlighting. It works well, but my fingers still keep trying to do the vi commands.
 

Attachments

  • vimrc.txt
    2.4 KB · Views: 148
  • gvimrc.txt
    1.8 KB · Views: 129
If it works locally but on when hosted, it's likely an issue with the path to the css file. The request for the css ("css/formatting.css") is probably not being resolved to the location you expect. Try using a path relative to your header.php.

I get syntax color with vim and gvim, but then I've been using the same .gvimrc and .vimrc files for years, copying from machine to machine, and I don't really know what's different between my rc files and the defaults.

Actually, I just remembered. Try typing ":syntax on" when you're editing. You can add that to .vimrc
and .gvimrc. I prefer gvim, by the way. Edit: I've uploaded my .gvimrc and .vimrc if you want to take a look. Copy gvimrc.txt to your home directory as .gvimrc and vimrc.txt as .vimrc (backup your own copies first, if you have them)

I've also used TextWrangler, which has syntax highlighting. It works well, but my fingers still keep trying to do the vi commands.

Thanks for the vim tips.

As for the relative path, that path is correct. header.php resides in the same directory that also contains the css folder. I kept the directory structure in tact when uploading to my server. I don't see why this isn't working unless it could be a permissions issue. Is this likely?
 
What do you get when you type http://host/path/css/formatting.css ... where host is your hosted server, and path is the the path to your header.php (which may be empty)?

If your page isn't loading the css file, the path to it likely to be wrong, no matter what you think is right. I've had this issue myself, and modifying the path usually fixes it. This is especially an issue where you're including a file containing the link to a css or image.

If your directory structure is like:

Code:
|- header.php
|- css
    |- formatting.css

try changing your css path to "./css/formatting.css"
 
What do you get when you type http://host/path/css/formatting.css ... where host is your hosted server, and path is the the path to your header.php (which may be empty)?

If your page isn't loading the css file, the path to it likely to be wrong, no matter what you think is right. I've had this issue myself, and modifying the path usually fixes it. This is especially an issue where you're including a file containing the link to a css or image.

If your directory structure is like:

Code:
|- header.php
|- css
    |- formatting.css

try changing your css path to "./css/formatting.css"


I get this message trying to go to the css file directly:

Forbidden

You don't have permission to access /sandbox/css/formatting.css on this server.


Also, I've tried the ./css/formatting.css as well with the same results.
 
Wow, I just fixed the problem by giving the folder chmod 755...I wonder why it didn't have these permissions by default.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.