Jump to content

Complete newbie question....


dazzathedrummer

Recommended Posts

Hi,

 

I'm new to php but have an understanding of html and SQL.

 

I'm trying to get a simple login system working on my bands website, i've got the code working ok, I'm just wondering why the page isn't working properly in IE.

 

I basically followed the about.com tutorials to get the files working and then I took the websites main index.html, saved it in a test location as members.php and pasted in the php code at the top.

 

It works fine and displays perfectly in firefox, Chrome and Safari, but looks wrong in IE, almost as if its not using the css.

 

any ideas would be greatly appreciated,

 

the page is here

 

www.the-guards.org.uk/private/members

 

thanks,

 

darren

Link to comment
Share on other sites

This is a css issue, not php. It's because of a floating issue.

 

The quickfix is to make sure you specify this for you #container div:

 

Change width to whatever you like - but you must specify a width for this to work.

 

#container{width:500px;float:none;margin: 0 auto;}

 

Also, do this for the #Container_bottom - you can do both at same time like this:

 

#container, #Container_bottom{width:500px;float:none;margin: 0 auto;}

 

Try it out see what it does.

 

Hope that helps.

Link to comment
Share on other sites

Hi,

 

Thanks for your reply, I'm at work at the moment so I cant try it out but I will do when I get home.

 

Is it really just a case of specifying the width in the CSS?

 

I'm having trouble following the logic on that.....

 

- I take a html page that works fine (www.the-guards.org.uk)

- I save it down as a .php - works fine in all browsers

- I add some php code - it works fine in all browsers except IE

 

I'm not saying that your wrong, i'd just like to understand how that works.

 

thanks,

 

Darren

Link to comment
Share on other sites

I'd hazard a guess that it may probably be due to the way the code is being interpreted. IE sometimes likes it one way, but when the code is passed to be the browser another way such as through a php server IE could flip out if everything is not set as it should be.

 

Meaning that sometimes non-standard code will be fine straight from html file then on rare occasions flip out if not standard from something else. (Standards accourding to IE that is... since IE doesn't seem to follow the true standards half the time anyways.)  Recommended to do the changes mentioned anyways to meet standard code used frequently, but alternatively I've fixed the screwy IE issues by just playing around.... try putting all the html code inside the php code with something like this method to see if IE likes it. Not the best thing in the world to do, but if you get more into php you'll love doing this for bits and pieces.

<?php
echo('
<html>
<body>
Hello!
</body>
</html>
'); ?>  

Link to comment
Share on other sites

Hi,

 

Thanks for your reply, I'm at work at the moment so I cant try it out but I will do when I get home.

 

Is it really just a case of specifying the width in the CSS?

 

I'm having trouble following the logic on that.....

 

- I take a html page that works fine (www.the-guards.org.uk)

- I save it down as a .php - works fine in all browsers

- I add some php code - it works fine in all browsers except IE

 

I'm not saying that your wrong, i'd just like to understand how that works.

 

thanks,

 

Darren

 

Right I see. Well, I don't entertain opinion so if I say this is the solution - it is. But, as I mentioned, it is only the 'quick fix'. It's a simply css statement which will resolve the centering issue. gwolgamott is right too and although it is extremely rare this happens, it can still happen. It's rare because fact is, php is serving exactly the same html, so if something doesn't add up in one browser - it's a browser compatibility issue due to bad html (or with ie..standard html).

 

To determine exactly why you adding php code is affecting the layout, we'd have to know exactly what code you're adding and where you're adding it. Like if you added php code before the html header (with no whitespace) - and didn't return to output, there is no way any browser will see a different page. So you must be outputting something which is breaking the layout.

 

Try my quick fix though - failing that, send some more details over and I'm sure they'll be a better solution.

Link to comment
Share on other sites

also the fact that this appears in the source above the header:

Welcome to our site! <a href=login1.php>Login</a> or <a href=reg1.php>register</a>
<html>
<head>

That is most likely a more viable reason as well for issues. There should be nothing above the <body> tag that you want to display. If that is php generated then put your code immediately below the <body> tag before any of you other code.  As Anti-M said give a snippet of the php code and html beginning code so we can direct you further.

 

Link to comment
Share on other sites

also the fact that this appears in the source when using firefox above the header:

Welcome to our site! <a href=login1.php>Login</a> or <a href=reg1.php>register</a>
<html>
<head>

That is most likely a more viable reason as well for issues. There should be nothing above the <body> tag that you want to display. If that is php generated then put your code immediately below the <body> tag before any of you other code.  As Anti-M said give a snippet of the php code and html beginning code so we can direct you further.

 

Good point ;) that will cause issues any way.

Link to comment
Share on other sites

Thanks guys, I really appreciate the help - as I said, I'm completely new to php, so if i question your responses, i'm just trying to understand how it works and i don't mean to imply any disrespect or even doubt.

 

I will have a go at implementing the above suggestions when I get home from work this evening.

 

I'm still getting to grips with where things should appear in the script and how all of that works.

 

Ideally I'd like the 'welcome' and login/out/register details to appear under the youtube video, but I dont really understand how to put that in that Div without getting an error about setting headers - but i'll get to that later, once i've got to grips with running the html and php from the php file.

 

All I did was take the html at www.the-guards.co.uk and add the following: -

<code>

<?php

 

$Month = 2592000 + time();

 

//this adds 30 days to the current time

 

setcookie(AboutVisit, date("F jS - g:i a"), $Month);

if(isset($_COOKIE['AboutVisit']))

 

{

$username = $_COOKIE['ID_my_site'];

$last = $_COOKIE['AboutVisit'];

 

echo "Welcome back $username <br> You last visited on ". $last, " ";

 

}

 

else

 

{

 

    echo "Welcome to our site! ";

 

}

// Connects to your Database

mysql_connect("database.lcn.com", "LCN_7792", "theguards9402") or die(mysql_error());

mysql_select_db("the_guards_org_uk_users") or die(mysql_error());

 

 

//checks cookies to make sure they are logged in

if(isset($_COOKIE['ID_my_site']))

{

$username = $_COOKIE['ID_my_site'];

$pass = $_COOKIE['Key_my_site'];

$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

while($info = mysql_fetch_array( $check ))

{

 

//if the cookie has the wrong password, they are taken to the login page

 

if ($pass != $info['password'])

{ header("Location: login1.php");

}

 

//otherwise they are shown the admin area

else

{

echo "You are currently logged in<p>";

echo "<a href=logout1.php>Logout</a>";

}

}

}

else

echo "<a href=login1.php>Login</a>", " or ", "<a href=reg1.php>register</a>";

?>

</code>

 

 

Link to comment
Share on other sites

Ah.. What's going on here is that the php code echos out (prints out) some lines like welcome and a link and whatnot.... before the head of the page. So when php server sends the page to the browser it's sending text and links before the <head> & <body> tags. That is why, you are essentially creating non-compliant code that IE seems to be the only one that cares if it is in this instance causing the css (As Anti-M mentioned) layout to get messed up. Quickly fix that by moving the php code further down to be in the body tag.... see below. As far also to move it where you want it... create a div for the php within... if you want nice looking code could also create an include for the php.

 

</head>

<body bgcolor="#000000" background="Images/background.jpg">
<!-- ------------------PUT YOUR PHP CODE JUST ABOVE HERE--------------------------- -->
<div id="container">
  <div id="banner">
    <ul id="Guards_menu" class="MenuBarHorizontal">
      <li><a href="index.html">Home</a>      </li>
      <li><a href="gigs.html">Gigs</a></li>

Link to comment
Share on other sites

OK, that makes sense to me - it seems logical, but as soon as i get to  "setcoockie" I get the "Cannot modify header information...." error because its beloe the head eleiment - and presumably it will do this when it gets to "{ header("Location: login1.php"); " as well.

 

This is the bit that confuses me!

 

... incidentally, what forum code are you using to display the code above? I tried <code></code> but it didn't work .

Link to comment
Share on other sites

OK, that makes sense to me - it seems logical, but as soon as i get to  "setcoockie" I get the "Cannot modify header information...." error because its beloe the head eleiment - and presumably it will do this when it gets to "{ header("Location: login1.php"); " as well.

 

This is the bit that confuses me!

 

... incidentally, what forum code are you using to display the code above? I tried <code></code> but it didn't work .

 

Use  code wrapped with [] instead of <> - or any bbcode you know should work fine here.

 

On the headers already sent - that is common when first using php so don't worry. I sometimes get it even now after 5 years.

 

The problem is, if you have used 'print' or 'echo' within your code, headers have been sent and php cannot modify those headers which means you cannot modify cookies.

 

What you need to do is manage all header information like cookies and sessions prior to running your main code. If you use an include within the html, you cannot modify any cookie information but only validate it.

 

But to explain better say you have a piece of html that should only show if someone is logged in - you do this:

 

<?php session_start();

if(//user is logged in){
  $html = '<b>you are logged in</b>';
}else{
  $html = '<div id="loginform">login form goes here</div>';
}

//Then, in your html you can use:

<?php echo $html; ?>

 

But setcookie() and header() along with many others can only be done BEFORE you 'echo', 'print' or otherwise send anything to the browser.

 

It's a hard concept to grasp at first but you'll get the hang of it. Really hope that helps. Let me know if you have any other questions or need me to clarify anything.

Link to comment
Share on other sites

Well thanks to all above - i've got the code working now (although I haven't implemented it yet).

 

My only problem now is the strange IE formatting behaviour.

 

I've made the changes to the Float and width attributes, but it hasn't made any difference - is there a 'best place' to declare/link the css within a php file?

Link to comment
Share on other sites

You have no doctype...

 

Therefore IE is rendering in quirks mode.

 

Add the following at the very top of the page and it should solve most if not all IE problems.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

or

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

Make sure that nothing is before the doctype, not even a blank space.

Link to comment
Share on other sites

You have no doctype...

 

Therefore IE is rendering in quirks mode.

 

Add the following at the very top of the page and it should solve most if not all IE problems.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

or

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

Make sure that nothing is before the doctype, not even a blank space.

 

That sorts out the IE layout problem - but now I get php header errors where it was working before?!?!?!

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//this adds 30 days to the current time 
$setcookie = setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>
<html>...........


<head>

 

the file itself is a .php that i'm trying to run html within and associate a css to.

 

 

Link to comment
Share on other sites

Sorry, I just realised that what I wrote was not very clear lol.

 

The doctype needs to be the first piece of code the browser sees not the first piece that the server sees.

 

Hope that makes more sense :D

 

the following should work

 

<?php
//this adds 30 days to the current time 
$setcookie = setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>...........


<head>

Link to comment
Share on other sites

Sorry, I just realised that what I wrote was not very clear lol.

 

The doctype needs to be the first piece of code the browser sees not the first piece that the server sees.

 

Hope that makes more sense :D

 

the following should work

 

<?php
//this adds 30 days to the current time 
$setcookie = setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>...........


<head>

 

ahhh, I get it!

 

That looks like its done the trick - thank you (and everyone else) very much!!!

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.