Jump to content

[SOLVED] Applying CSS into PHP


TheJoey

Recommended Posts

Ive been trying to do this but it just doesnt show up the same as it does when i do it in html.

<?php 
session_start();
?>
<html>
<head>
<link rel="stylesheet" href="assets/css/style.css" type="text/css" media="all" />
</head>
<body>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array
$find = "$username:$password"; // form a string like you expect it to be in the array
if(in_array($find,$lines)){
   $_SESSION['loginsuccessfull'] = true;
   echo    echo '<div id="wrapper">
  <div id="header">
    <p class="logotext">NEw Stop <strong>Shop</strong><br>
      <span class="logotext2">Blah blah blah</span></p>
    <div id="nav">
      <ul>
        <li><a href="">Site Map</a></li>
        <li><a href="">Privacy Policy</a></li>
        <li><a href="">Products</a></li>
        <li><a href="">Registration</a></li>
        <li><a href="index.html" class="on">Home</a></li>
      </ul>
    </div>
  </div>
  <div id="content">
    <div id="left">
      <h2>Addition Links</h2>
      <ul>
        <li><a href="">WHOOP WHOPP</a></li>
        <li><a href="">LOCATE US</a></li>
	<li><a href="">= Us</a></li>
        <li><a href="">2Us</a></li>
        </li>
      </ul>
    </div>
    <div id="breadcrumb"><strong>Home</strong></div>
    <div id="right">
      <h1>NEW STOP SHOP</h1>
      <p>Login successfull</p>
</div>';
} else {
   echo '<div id="wrapper">
  <div id="header">
    <p class="logotext">NEw Stop <strong>Shop</strong><br>
      <span class="logotext2">Blah blah blah</span></p>
    <div id="nav">
      <ul>
        <li><a href="">Site Map</a></li>
        <li><a href="">Privacy Policy</a></li>
        <li><a href="">Products</a></li>
        <li><a href="">Registration</a></li>
        <li><a href="index.html" class="on">Home</a></li>
      </ul>
    </div>
  </div>
  <div id="content">
    <div id="left">
      <h2>Addition Links</h2>
      <ul>
        <li><a href="">WHOOP WHOPP</a></li>
        <li><a href="">LOCATE US</a></li>
	<li><a href="">= Us</a></li>
        <li><a href="">2Us</a></li>
        </li>
      </ul>
    </div>
    <div id="breadcrumb"><strong>Home</strong></div>
    <div id="right">
      <h1>NEW STOP SHOP</h1>
      <p>Login Unsuccesfull</p>
</div>';
}
?>
</body>
</html>

 

Also when i click to go home, it gives me echo's "login unsuccessfull" before sending me back to home.

Link to comment
Share on other sites

Hi, when you say "it just doesnt show up the same as it does when i do it in html." what do you mean?

I can't see any css in your code that is related to the php.

 

Not sure if it is your problem, but this line has a double "echo":

echo    echo '<div id="wrapper">

 

Also, unlesss there is more code than you have posted here, you are not actually saving the valid users logged in session so I am not surprised that when you click on a link it says "login unsuccessful"

 

Sorry to not be of more help, it is just that I can't see exactly what (which) your problem is.

 

Chris

 

 

Link to comment
Share on other sites

Hi,

Well im currently not at home, the css works fine in html.

Well, as I say, I see no css-php related isssues here.

 

So what page is this ?

Is it the page after a login attempt?

 

It is true that these lines:

$username = $_POST['username'];
$password = $_POST['password'];
$lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array
$find = "$username:$password"; // form a string like you expect it to be in the array
if(in_array($find,$lines)){
   $_SESSION['loginsuccessfull'] = true;

are setting a logged in $_SESSION.  However,  in the code that you have shown this only works if the values "username" and "password" are "posted" to the page.

This normally only happens when the login form has been posted, not on every page.

 

Ideally the login for would go to an "invisible" page that did nothing more than check the login values, if correct it would set the session variable as you have here, then redirect, using php header(), to the (eg) home page.  If incorrect it would go somewhere else, cleary not defining the session.

Then, on all pages that require the session variable you would check for that something like:

session_start();
// check user is logged in - if not redirect
if(!$_SESSION["loginsuccessfull"]) header("location: url_to_other_page");
// user logged in - show page.....

 

Chris

Link to comment
Share on other sites

im unsure where i put my redirect. So i play it on the same page as my login script correct?

Because when i try do that it doesnt allow me to use else

<?php 
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array
$find = "$username:$password"; // form a string like you expect it to be in the array
if(in_array($find,$lines)){
   $_SESSION['loginsuccessfull'] = true;
{
if(!$_SESSION["loginsuccessfull"]) header("location: loginsuccess.php");
} else {
$_SESSION["loginsuccessfull"] header("location: loginunsuccess.php");
}
?>

ive never used a header before sorry

Link to comment
Share on other sites

Nearly there....

 

Try this:

<?php 
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array
$find = "$username:$password"; // form a string like you expect it to be in the array
if(in_array($find,$lines)){
   $_SESSION['loginsuccessfull'] = true;  # define session var
   header("location: loginsuccess.php");  # redirect to  success page
} else {
  header("location: loginunsuccess.php");
}
?>

 

Then, as TheJoey says, don't forget to start every page with session_start();

 

Chris

 

 

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.