GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 24-Jul-2003, 09:26
samtediou samtediou is offline
New Member
 
Join Date: Jul 2003
Posts: 18
samtediou is an unknown quantity at this point
Hmmmm,

I double-checked both example_login.php and example_logout.php for any whitespace before and after <?php ?>, and found out that my host's user interface automatically adds one blank line to the end of the file on every save.

So if I modify a clean example_logout.php five times and save after each modification, example_login.php will have 5 blank lines at the end of the file.

So instead I modified these files on my desktop and uploaded them, instead of modifying them through the host's user interface. That was the 'save file' button on the host GUI wouldn't work its line-adding activity.

Unfortunately, I still get the same error when I try to login on a previously used browser or simply try to logout of the application.

Is anybody else getting this error message, or is it just me?

Thanks,

samtediou
  #12  
Old 24-Jul-2003, 10:57
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I'll try to upload a set to my website and see if I can reproduce the error; otherwise you're on your own buddy!

BTW, there's something you can do to quickly get rid of this warning in the meantime. Just stick this line in at the top of example_session_functions.php:
PHP Code:

<?php

ob_start();
// then the rest of the original code here

?>

  #13  
Old 24-Jul-2003, 12:56
samtediou samtediou is offline
New Member
 
Join Date: Jul 2003
Posts: 18
samtediou is an unknown quantity at this point
Smile

Excellent! The password-protected pages are working perfectly now! It's good to learn a bit about output buffering. Thanks so much.

Samtediou
  #14  
Old 03-Sep-2003, 15:08
BurtNoir BurtNoir is offline
New Member
 
Join Date: Sep 2003
Location: Toronto
Posts: 1
BurtNoir is an unknown quantity at this point

Good stuff but...


Thanks for posting this stuff here. I have it working nicely now.

I just thought I'd share a couple of things I found while testing on my setup.

The define of URL_LOGIN_PAGE should come before session_start(). Otherwise the verify valid user stuff can't send you back to the login page like it should. You can try this out by pointing your browser directly at one of the secret pages.

While I was trying to figure out the previous thing I discovered the part of the php manual dealing with the header function. To be super correct I changed all my header redirects to the following:

die( header("Location: http" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . URL_LOGIN_PAGE) );

This simply generates an absolute reference to the page you are redirecting to. Apparently this is more portable.

If I've made any stupid errors here please forgive as PHP and I are celebrating our 1 week anniversary
  #15  
Old 05-Sep-2003, 19:47
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Re: Good stuff but...


Hello BurtNoir,

We wrote, tested and discussed this a while back so I cannot really confirm your comment below. However, I did edit the code to reflect the change you suggested - since it does make more sense just following the natural flow of the script.
Quote:
Originally posted by BurtNoir
...The define of URL_LOGIN_PAGE should come before session_start(). Otherwise the verify valid user stuff can't send you back to the login page like it should...

The following is just a matter of personal preference. I personally prefer to keep my links 'relative', while some others, like yourself, prefer otherwise - there is no such thing as being super correct in this situation.
Quote:
To be super correct I changed all my header redirects to the following:

die( header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . URL_LOGIN_PAGE) );

This simply generates an absolute reference to the page you are redirecting to. Apparently this is more portable.

Thank you for your feedback, I appreciate it. :)
  #16  
Old 21-Mar-2004, 15:25
PHPSam PHPSam is offline
New Member
 
Join Date: Mar 2004
Posts: 1
PHPSam is on a distinguished road

Multiply passwords and usernames


Hello, I am Sam. I am eager to learn PHP. How do I make multiply passwords and usernames using the codes from PHP sessions to password-protect web pages.

Thank you very much for helping me out. :-)
  #17  
Old 10-Aug-2004, 23:40
BurtStark BurtStark is offline
New Member
 
Join Date: Aug 2004
Posts: 1
BurtStark is on a distinguished road
Nice tutorial, JdS. I found it really helpful. In fact, it prompted me to join the forums here.

I came across an interesting anomaly regarding the subject that you and BurtNoir were discussing in the quotes below. I found that if I used an absolute reference to the initial 'secret page' in the 'EXAMPLE_SESSION_FUNCTIONS.PHP' script, that I would have to logon twice to access the protected page. It was as if the first login didn't take at all. Once I changed the page's reference to a relative path, it worked the first time, every time.

I'm fairly new to PHP and can't begin to explain why using a relative path worked better in my case. I just thought I'd share my observation in case somebody else finds it helpful.

Quote:
Originally Posted by JdS
The following is just a matter of personal preference. I personally prefer to keep my links 'relative', while some others, like yourself, prefer otherwise - there is no such thing as being super correct in this situation.

Quote:
Originally Posted by BurtNoir
To be super correct I changed all my header redirects to the following:

die( header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . URL_LOGIN_PAGE) );

This simply generates an absolute reference to the page you are redirecting to. Apparently this is more portable.

  #18  
Old 11-Aug-2004, 07:53
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello BurtStark,

Thank you for the feedback. I am glad the example PHP script helped you understand a little bit of what you're trying to do yourself. I am also glad that you took the trouble to register, activate your account, login and reply to this thread just to say so.

About the "relative vs. absolute" thingy, I never really looked into it since I am not much of a "detail" person, unless it's something I am writing for myself

I can however tell you that using relative paths (as in the example) is the normal thing to do.
  #19  
Old 28-Jun-2006, 06:42
mea99 mea99 is offline
New Member
 
Join Date: Jun 2006
Posts: 1
mea99 is on a distinguished road

Re: sessions problem


JdS,

Just wanted to say thanks for all the information. I'm new to PHP etc and its v. difficult to learn whilst trying to produce a working site for your customers in a hurry! I'm kinda learning backwards, but its a start.

One quick question - is it possible to echo a comment on the login page if a user submits incorrect (or blank) details? e.g. "please complete all requied fields"

Thanks again.
  #20  
Old 18-Jan-2007, 12:34
l0ckm4 l0ckm4 is offline
New Member
 
Join Date: Jan 2007
Posts: 1
l0ckm4 is on a distinguished road
Question

Re: sessions problem


Hi - I came across this post yesterday and it does 90% of what i need to do and it was very easy to implement so thank you for posting it.

I was wondering if it is possible to somehow set something somewhere (maybe on the mysql database) to tell the system that the user is logged in and then if someone tries to log in using the same details then they would get an error. I am pretty sure i can do this by adding a logged in field to my database and when the user logs in this action sets the field to true and when the user logs out sets it back to false. I am having trouble though figuring out what to do if the user just closes down their browser as the field would stay set and then they would not be able to log in again until I reset it.

Can anyone come up with any solution/suggestion for me please?

Many thanks in advance,

Mark
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache / PHP problem, maybe output length? HaganeNoKokoro Apache Web Server Forum 3 07-Aug-2008 05:42
php sessions mrjameer MySQL / PHP Forum 0 24-Oct-2006 06:26
Problem with executing PHP in webpage fdgloworm Apache Web Server Forum 0 13-Feb-2006 12:43
Php Sessions & Smarty Templating Engine ohm_ MySQL / PHP Forum 0 18-Jan-2006 01:42
Alt. Problem: PHP 4.4 GD compilation errors Fezzen Computer Software Forum - Linux 2 12-Aug-2005 22:16

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:58.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.