FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php sessions and css file?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
php sessions and css file? [message #173664] Tue, 26 April 2011 14:46 Go to next message
Alex Pavluck is currently offline  Alex Pavluck
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
Is it possible to use a css file if you are using php sessions to
login?

Here is my code:

valid.php
.....
if($count==1){

$_SESSION['loggedin'] = 1;// Set session variable
header("Location: protect.php");//header must be the first printed
line!

protect.php
<?php
session_start();
// Call this function so your page
// can access session variables
if($_SESSION['loggedin'] != 1) {
// If the 'loggedin' session variable
// is not equal to 1, then you must
// not let the user see the page.
// So, we'll redirect them to the
// login page (login.php).
header("Location: index.html");
exit;
}
?>


<html>
<head>
<title>DOLF Project Log In</title>
<link rel="stylesheet" type="text/css" href="layout.css"
media="screen" />

</head>
<body>
.....
Re: php sessions and css file? [message #173665 is a reply to message #173664] Tue, 26 April 2011 15:03 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2011 4:46 PM, Alex Pavluck wrote:
> Is it possible to use a css file if you are using php sessions to
> login?

Yes, they are completely different concepts.
So, unless you try to mix them somehow, they have nothing to do with
each other.


>
> Here is my code:
>
> valid.php
> ....
> if($count==1){
>
> $_SESSION['loggedin'] = 1;// Set session variable
> header("Location: protect.php");//header must be the first printed
> line!


Did you add an:
exit;
after that header?

>
> protect.php
> <?php
> session_start();
> // Call this function so your page
> // can access session variables
> if($_SESSION['loggedin'] != 1) {
> // If the 'loggedin' session variable
> // is not equal to 1, then you must
> // not let the user see the page.
> // So, we'll redirect them to the
> // login page (login.php).
> header("Location: index.html");
> exit;
> }
> ?>
>
>
> <html>
> <head>
> <title>DOLF Project Log In</title>
> <link rel="stylesheet" type="text/css" href="layout.css"
> media="screen" />
>
> </head>
> <body>
> ....


You didn't describe your problem.

A wild suggestion: look into the source of the resulting webpage.
Possibly you will see a warning/notice that makes your HTML invalid
enough for the browser to ignore the css.

Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: php sessions and css file? [message #173666 is a reply to message #173664] Tue, 26 April 2011 15:09 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2011 10:46 AM, Alex Pavluck wrote:
> Is it possible to use a css file if you are using php sessions to
> login?

Why not? What has one thing to do with the other. If you are chewing
gum, can you write on a piece of paper? See what I mean?

One thing you need to get clear in your mind: PHP is _SERVER SIDE_
code. It has absolutely _NOTHING_ to do with the display. CSS is
_CLIENT SIDE_ code and ONLY has to do with the display. Yes, using PHP
you can code print or echo statements of html code do display to the
browser, and when done it will use the CSS that is included in the
output, but ALL of that is done on the server. It is only when it gets
to the browser -- and has absolutely NO knowledge that PHP, ASP or
anything else on the server generated it -- that it uses the CSS.

BTW, you are NOT using php sessions to log in. You are using php
sessions to remember and determine _IF_ you are logged in.

>
> Here is my code:
>
> valid.php
> ....
> if($count==1){
>
> $_SESSION['loggedin'] = 1;// Set session variable
> header("Location: protect.php");//header must be the first printed
> line!
>
> protect.php
> <?php
> session_start();
> // Call this function so your page
> // can access session variables
> if($_SESSION['loggedin'] != 1) {
> // If the 'loggedin' session variable
> // is not equal to 1, then you must
> // not let the user see the page.
> // So, we'll redirect them to the
> // login page (login.php).
> header("Location: index.html");
> exit;
> }
> ?>
>
>
> <html>
> <head>
> <title>DOLF Project Log In</title>
> <link rel="stylesheet" type="text/css" href="layout.css"
> media="screen" />
>
> </head>
> <body>
> ....

Now, looking at your code I have no idea what $count comes from, nor
what $valid is used for. From appearances it looks like you will send
the user to the index.html (NOT the login page, unless the index page IS
the log in page) if that $count variable is somehow not equal to one.

Also, from the way you put it here, I thing you REALLY want protect.php
to be terminated after the ?>. You would then have a

<?php
require_once 'protect.php"
?>

at the top of every file you want to protect (before the <html> line).
Remember that everything between the <?php and the ?> is processed on
the server BEFORE it is delivered to the browser.

Oh, you also need an actual log in page for the user to put in a user
name and a password. That is where you would set the session variable.

--
Shelly
Re: php sessions and css file? [message #173667 is a reply to message #173664] Tue, 26 April 2011 17:08 Go to previous messageGo to next message
Alex Pavluck is currently offline  Alex Pavluck
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
Thanks for the comments. I guess I didn't explain my problem well.
The issue is in the protect.php file if I take the code and cut out
only the html and paste it into works.html then the css file works.
If I either name the file php then the css doesn't work.


On Apr 26, 10:46 am, Alex Pavluck <apavl...@gmail.com> wrote:
> Is it possible to use a css file if you are using php sessions to
> login?
>
> Here is my code:
>
> valid.php
> ....
> if($count==1){
>
>                 $_SESSION['loggedin'] = 1;// Set session variable
>                 header("Location: protect.php");//header must be the first printed
> line!
>
> protect.php
> <?php
>     session_start();
>     // Call this function so your page
>     // can access session variables
>         if($_SESSION['loggedin'] != 1) {
>         // If the 'loggedin' session variable
>         // is not equal to 1, then you must
>         // not let the user see the page.
>         // So, we'll redirect them to the
>         // login page (login.php).
>         header("Location: index.html");
>         exit;
>     }
> ?>
>
> <html>
> <head>
> <title>DOLF Project Log In</title>
> <link rel="stylesheet" type="text/css" href="layout.css"
> media="screen" />
>
> </head>
> <body>
> ....
Re: php sessions and css file? [message #173668 is a reply to message #173667] Tue, 26 April 2011 17:50 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2011 1:08 PM, Alex Pavluck wrote:
> Thanks for the comments. I guess I didn't explain my problem well.
> The issue is in the protect.php file if I take the code and cut out
> only the html and paste it into works.html then the css file works.
> If I either name the file php then the css doesn't work.
>
>
> On Apr 26, 10:46 am, Alex Pavluck<apavl...@gmail.com> wrote:
>> Is it possible to use a css file if you are using php sessions to
>> login?
>>
>> Here is my code:
>>
>> valid.php
>> ....
>> if($count==1){
>>
>> $_SESSION['loggedin'] = 1;// Set session variable
>> header("Location: protect.php");//header must be the first printed
>> line!
>>
>> protect.php
>> <?php
>> session_start();
>> // Call this function so your page
>> // can access session variables
>> if($_SESSION['loggedin'] != 1) {
>> // If the 'loggedin' session variable
>> // is not equal to 1, then you must
>> // not let the user see the page.
>> // So, we'll redirect them to the
>> // login page (login.php).
>> header("Location: index.html");
>> exit;
>> }
>> ?>
>>
>> <html>
>> <head>
>> <title>DOLF Project Log In</title>
>> <link rel="stylesheet" type="text/css" href="layout.css"
>> media="screen" />
>>
>> </head>
>> <body>
>> ....
>

Look at your page source in the browser. Is it what you expected?

File names have nothing to do with css. Your problem is elsewhere.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: php sessions and css file? [message #173669 is a reply to message #173667] Tue, 26 April 2011 19:29 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2011 1:08 PM, Alex Pavluck wrote:
> Thanks for the comments. I guess I didn't explain my problem well.
> The issue is in the protect.php file if I take the code and cut out
> only the html and paste it into works.html then the css file works.
> If I either name the file php then the css doesn't work.

You still didn't explain it well. What I _THINK_ you are saying is:
(a) if you remove the <?php ... ?> from protect.php and run
protect.php, then it doesn't show the effect of layout.css

and

(b) If you then rename that file that no longer contains php and call it
works.html then it does show the effects of layout.css.

Is that what you are saying? If you are, then it makes no sense since
file names are irrelevant (can be either htm, html or php).

>
>
> On Apr 26, 10:46 am, Alex Pavluck<apavl...@gmail.com> wrote:
>> Is it possible to use a css file if you are using php sessions to
>> login?
>>
>> Here is my code:
>>
>> valid.php
>> ....
>> if($count==1){
>>
>> $_SESSION['loggedin'] = 1;// Set session variable
>> header("Location: protect.php");//header must be the first printed
>> line!
>>
>> protect.php
>> <?php
>> session_start();
>> // Call this function so your page

There is no "function" being called here

>> // can access session variables
>> if($_SESSION['loggedin'] != 1) {

You indentation is improper.

>> // If the 'loggedin' session variable
>> // is not equal to 1, then you must
>> // not let the user see the page.
>> // So, we'll redirect them to the
>> // login page (login.php).
>> header("Location: index.html");
>> exit;
>> }
>> ?>
>>
>> <html>
>> <head>
>> <title>DOLF Project Log In</title>
>> <link rel="stylesheet" type="text/css" href="layout.css"
>> media="screen" />
>>
>> </head>
>> <body>
>> ....
>
Does you source code from the BROWSER (the result -- view page source)
indicate items in the css for different elements? How is it being
improperly displayed?

--
Shelly
Re: php sessions and css file? [message #173670 is a reply to message #173664] Tue, 26 April 2011 19:53 Go to previous messageGo to next message
Alex Pavluck is currently offline  Alex Pavluck
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
I found the answer by using Google as usual. The answer is a simple
absolute vs relative path for the css file for those who care. Here
is the site: http://www.tek-tips.com/viewthread.cfm?qid=1448368&page=67

Special thanks to the people who made sarcastic rather helpful posts.
Next time don't post on questions if you aren't going to be helpful -
it isn't as impressive or cool as you think.





On Apr 26, 10:46 am, Alex Pavluck <apavl...@gmail.com> wrote:
> Is it possible to use a css file if you are using php sessions to
> login?
>
> Here is my code:
>
> valid.php
> ....
> if($count==1){
>
>                 $_SESSION['loggedin'] = 1;// Set session variable
>                 header("Location: protect.php");//header must be the first printed
> line!
>
> protect.php
> <?php
>     session_start();
>     // Call this function so your page
>     // can access session variables
>         if($_SESSION['loggedin'] != 1) {
>         // If the 'loggedin' session variable
>         // is not equal to 1, then you must
>         // not let the user see the page.
>         // So, we'll redirect them to the
>         // login page (login.php).
>         header("Location: index.html");
>         exit;
>     }
> ?>
>
> <html>
> <head>
> <title>DOLF Project Log In</title>
> <link rel="stylesheet" type="text/css" href="layout.css"
> media="screen" />
>
> </head>
> <body>
> ....
Re: php sessions and css file? [message #173671 is a reply to message #173670] Tue, 26 April 2011 20:05 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2011 3:53 PM, Alex Pavluck wrote:
> I found the answer by using Google as usual. The answer is a simple
> absolute vs relative path for the css file for those who care. Here
> is the site: http://www.tek-tips.com/viewthread.cfm?qid=1448368&page=67
>
> Special thanks to the people who made sarcastic rather helpful posts.
> Next time don't post on questions if you aren't going to be helpful -
> it isn't as impressive or cool as you think.

Next time:
a - Properly and completely describe the problem the first time
b - Explain just what the error is that you are getting
c - Detail what you have tried and the research you have done.
d - Don't make it sound like you don't know the difference between
server side code and client side (browser) code

IOW, do your homework first and properly show where you are being
stumped. You will then find many people willing to help.

From the way you wrote your post I took you to be a student trying to
learn php -- and still do, and that this was a homework assignment.

What you are saying above about relative paths and absolute paths has
absolutely _NO_ relation to the problem you described. If it can find
the css with the php section removed using a relative path, then it can
find it with the php section still in there using a relative path. So,
you did obviously did something completely different - like having the
one with the php section and the one without it in two separate
directories -- something you totally failed to mention when you
described your problem or, rather, tried to.

Oh, BTW, you're welcome.

--
Shelly
Re: php sessions and css file? [message #173672 is a reply to message #173670] Wed, 27 April 2011 05:58 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2011 9:53 PM, Alex Pavluck wrote:
> I found the answer by using Google as usual. The answer is a simple
> absolute vs relative path for the css file for those who care. Here
> is the site: http://www.tek-tips.com/viewthread.cfm?qid=1448368&page=67


Nonsense.

I am sure you didn't solve your problem.
I suspect there are errors (notices/warnings) in your source-html.

Did you check it, as everybody suggested so far?
Did you check your HTML?



>
> Special thanks to the people who made sarcastic rather helpful posts.
> Next time don't post on questions if you aren't going to be helpful -
> it isn't as impressive or cool as you think.

You are screwing up here by being vague and more (See sheldongs reply).
Nobody is trying to beat you up or something, we are all helping, but
you make it difficult for yourself.


Now, do yourself a favor and check that sourcecode.

Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: php sessions and css file? [message #173674 is a reply to message #173669] Thu, 28 April 2011 00:24 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
sheldonlg wrote:

> On 4/26/2011 1:08 PM, Alex Pavluck wrote:
>> On Apr 26, 10:46 am, Alex Pavluck<apavl...@gmail.com> wrote:
>>> protect.php
>>> <?php
>>> session_start();
>>> // Call this function so your page
>
> There is no "function" being called here
>
>>> // can access session variables

With emphasis on *here* (session_start()) *is* a function). Documentation
comments should be pre-comments (and multiline comments, to distinguish them
from disabling comments), not post-comments.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: php sessions and css file? [message #173675 is a reply to message #173674] Thu, 28 April 2011 00:30 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 4/27/2011 8:24 PM, Thomas 'PointedEars' Lahn wrote:
> sheldonlg wrote:
>
>> On 4/26/2011 1:08 PM, Alex Pavluck wrote:
>>> On Apr 26, 10:46 am, Alex Pavluck<apavl...@gmail.com> wrote:
>>>> protect.php
>>>> <?php
>>>> session_start();
>>>> // Call this function so your page
>>
>> There is no "function" being called here
>>
>>>> // can access session variables
>
> With emphasis on *here* (session_start()) *is* a function). Documentation
> comments should be pre-comments (and multiline comments, to distinguish them
> from disabling comments), not post-comments.

Yes, session_start() is, indeed, a function. However, I have never
encountered a comment set such as the above that was talking about prior
code (other than something like //end while loop). So, I looked for a
function below the commenting, found none, and made the appropriate
remark that no function is being called here.

(Furthermore, common practice is to use /* */ or /** */ for multiline
comments rather than a bunch of //.)

--
Shelly
Re: php sessions and css file? [message #173686 is a reply to message #173675] Thu, 28 April 2011 19:15 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
sheldonlg wrote:

> On 4/27/2011 8:24 PM, Thomas 'PointedEars' Lahn wrote:
>> sheldonlg wrote:
>>> On 4/26/2011 1:08 PM, Alex Pavluck wrote:
>>>> On Apr 26, 10:46 am, Alex Pavluck<apavl...@gmail.com> wrote:
>>>> > protect.php
>>>> > <?php
>>>> > session_start();
>>>> > // Call this function so your page
>>>
>>> There is no "function" being called here
>>>
>>>> > // can access session variables
>>
>> With emphasis on *here* (session_start()) *is* a function).
>> Documentation comments should be pre-comments (and multiline comments, to
>> distinguish them from disabling comments), not post-comments.
>
> Yes, session_start() is, indeed, a function. However, I have never
> encountered a comment set such as the above that was talking about prior
> code (other than something like //end while loop). So, I looked for a
> function below the commenting, found none, and made the appropriate
> remark that no function is being called here.
>
> (Furthermore, common practice is to use /* */ or /** */ for multiline
> comments rather than a bunch of //.)

I think I just said that.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(at)news(dot)demon(dot)co(dot)uk>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Adding a CDATA section
Next Topic: hai
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 06:59:01 GMT 2024

Total time taken to generate the page: 0.02800 seconds