Page 1 of 1

PHP newbie.... designing first website utilizing PHP

Posted: Sat Nov 15, 2008 12:43 pm
by xSmokechecKx
Dear Developing Gods.....

I have recently had a vision of this fantastic site, and have just designed all the templates and such. Today I shall finish all of my XHTML and also my CSS. There are a few things that I would like to use on the site to make it more attractable to prospective clients... however, I am still a newbie to PHP. I understand how to have a login form on the page that simply stores the users info into the MySQL DB, but I have a few other questions. Here it goes:

1. How, after the user logs in, would I get it to say "You are currently logged in as 'user'" at the top of the pages instead of having the username and password fields?
2. How do I generate a 'user' logout?
3. How do I create a downloads portion on my site... so that users can download .pdf files and such from the server?
4. What is the easiest way to add RSS to my page?
5. Is there anything else PHP that would go great on a Training/Resource site for Health?

Thank you for taking the time to help me. After I get going... I should be okay for a while. :mrgreen:

Very Respectfully,
Derek

Re: PHP newbie.... designing first website utilizing PHP

Posted: Sat Nov 15, 2008 3:17 pm
by califdon
Welcome to DevNetwork forums, Derek. Gee, I've been called lots of things, but never a God! I'll have to think about that one for awhile. :P

I only have time for a partial answer, but I'm sure others will supply more help. The way user logins are usually implemented is by checking a login/password pair in your users database, then if it is valid, create one or more Session Variables (see http://www.tizag.com/phpT/phpsessions.php). As you get further requests from the browser, you can confirm that the user has been authenticated by checking the value of the Session Variable. To logoff a user, you just unset the Session. I'll leave it to tutorials to explain the details of how to do those things.

As for replacing the login spaces with a "You are logged in..." message, again you simply check the Session Variable and display the appropriate part of the page. You could even do it using Ajax so that an entire new page doesn't have to be loaded, but that's the next step beyond what you asked.

In looking for ways to enhance your site, I suggest that you not think in terms of "what PHP can do" because it can do pretty much anything you want it to. Think in terms of "what would appeal to my viewers", especially anything that requires customization of a page, because that's precisely what PHP does: it makes it possible to send different data to the browser, depending on conditions that are known at the server prior to sending a page to the browser. So if you want to look up data in a database, maybe even a remote database, such as one of the several IP-address-to-geographic-location databases, or based on something that the user enters in a form and submits back to the server -- that's something you can probably do with PHP.

Re: PHP newbie.... designing first website utilizing PHP

Posted: Sat Nov 15, 2008 7:25 pm
by xSmokechecKx
Thank you very much! I will start studying tutorial on the above mentioned until I get some more help. That gets me pointed in a little better direction. :P

Very respectfully,
Derek

Re: PHP newbie.... designing first website utilizing PHP

Posted: Sun Nov 16, 2008 10:03 am
by xSmokechecKx
okay,....... another thing I'd like to add to my site:

When I create the session for users when they login.... I want them to have their own little profile page that others can view. I will then add another page to view members .... and want it to update with everyone that registers to my site. What would be the easiest way to perform this.... and how do I make certain pages viewable only to registered users?

Thank you very much Dev Gods....

Very respectfully,
Derek

Re: PHP newbie.... designing first website utilizing PHP

Posted: Sun Nov 16, 2008 12:31 pm
by califdon
You can do all those things and more, Derek, but only if you learn the language and acquire some practice in thinking through the logic that will result in the desired operations. There are no simple answers to questions like yours. The general answer is that it would take an experienced programmer hours or days or weeks to write the code required for each of those things. Obviously that can't be answered in a forum. That's what tutorials are for. Good luck and have fun learning PHP.

Re: PHP newbie.... designing first website utilizing PHP

Posted: Sun Nov 16, 2008 1:40 pm
by xSmokechecKx
Yup yup.... That is exactly what I am doing.... Tutorial, after tutorial, after theory, after articles, after tutorials. Just seeking a little more direction in the form of how exactly i would have to format the php to get it to do these things....

Anyways, my first post and question - How do I get the header or login spot to be replaced after the users session is registered. I have came up with something and was wondering if I am somewhat close.

<?php

session_start();
if(session_is_registered('username')){
echo 'You are currently logged in as $user.';
}
include("header2.php");

else{
header("Location:http://www.mydomain.com/login.html");
}

?>


header2.php would be the new header without the usernam and password fields. Am I somewhat heading in the right direction? Any help or advice would be greatly appreciated.

Very respectfully,
Derek

Re: PHP newbie.... designing first website utilizing PHP

Posted: Sun Nov 16, 2008 3:37 pm
by califdon
xSmokechecKx wrote:Anyways, my first post and question - How do I get the header or login spot to be replaced after the users session is registered. I have came up with something and was wondering if I am somewhat close.

Code: Select all

 
<?php
session_start();
if(session_is_registered('username')){ 
echo 'You are currently logged in as $user.'; // <--- must use double quotes, to interpret $user
}
 
include("header2.php");  // <--- this can't be between the end of the 'if' and the 'else'
 
else{
header("Location:http://www.mydomain.com/login.html");
}
 
?> 
You have several syntax errors there. Think of it this way:

Code: Select all

if( -something- ) {
 
    // everything you want to take place if the condition is true
 
} else {
 
    // everything you want to take place if the condition is NOT true
 
}
header2.php would be the new header without the usernam and password fields. Am I somewhat heading in the right direction? Any help or advice would be greatly appreciated.
Did you really mean "without"? If you intend that the header2 file should be included if the user is authenticated, I should think that you would want to show the header with the username and password. To do that, you have to embed those values IN the header file, not before it. In other words, header2.php must have the PHP code to display the data you want to display. Then you don't need the line "echo 'You are currently logged in as $user.'; "

Derek, you really need to learn this stuff from a tutorial or a book, not expect someone here in the Forum to teach it to you. It's not that we don't want to help, but it's just not an effective way to learn. If you are having trouble learning from tutorials, you should consider taking a class. Forums are good for questions like, "Why is the following piece of code not returning the data I want?", not "I want to learn a new programming language, please teach it to me."