PHP Login code integrating help....

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by rufussweetwater, Jul 18, 2009.

  1. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    I have a PHP login system that i need help integrating into my website. The following code is the specific code i need to be integrated into the other following code which is my login section on my site.

    Login code [this is the brains (or insides) of my login code]
    PHP:
    <? 
    /** 
    * Main.php 

    * This is an example of the main page of a website. Here 
    * users will be able to login. However, like on most sites 
    * the login form doesn't just have to be on the main page, 
    * but re-appear on subsequent pages, depending on whether 
    * the user has logged in or not. 

    * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) 
    * Last Updated: August 26, 2004 
    */ 
    include("include/session.php"); 
    ?> 

    <html> 
    <title>CYK Studios | Home</title> 
    <body> 

    <table> 
    <tr><td> 


    <? 
    /** 
    * User has already logged in, so display relavent links, including 
    * a link to the admin center if the user is an administrator. 
    */ 
    if($session->logged_in){ 
       echo "<h1>Logged In</h1>"; 
       echo "Welcome <b>$session->username</b> <br><br>" 
           ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;" 
           ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;"; 
       if($session->isAdmin()){ 
          echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;"; 
       } 
       echo "[<a href=\"process.php\">Logout</a>]"; 

    else{ 
    ?> 

    <h1>Login</h1> 
    <? 
    /** 
    * User not logged in, display the login form. 
    * If user has already tried to login, but errors were 
    * found, display the total number of errors. 
    * If errors occurred, they will be displayed. 
    */ 
    if($form->num_errors > 0){ 
       echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>"; 

    ?> 
    <form action="process.php" method="POST"> 
    <table align="left" border="0" cellspacing="0" cellpadding="3"> 
    <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> 
    <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> 
    <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>> 
    <font size="2">Remember me &nbsp;&nbsp;&nbsp;&nbsp; 
    <input type="hidden" name="sublogin" value="1"> 
    <input type="submit" value="Login"></td></tr> 
    <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr> 
    <tr><td colspan="2" align="left"><br> 
    Not registered? <a href="register.php">Sign-Up</a></td> 
    </tr> 
    </table> 
    </form> 

    <? 


    /** 
    * Just a little page footer, tells how many registered members 
    * there are, how many users currently logged in and viewing site, 
    * and how many guests viewing site. Active users are displayed, 
    * with link to their user information. 
    */ 
    echo "</td></tr><tr><td align=\"center\"><br><br>"; 
    echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>"; 
    echo "There are $database->num_active_users registered members and "; 
    echo "$database->num_active_guests guests viewing the site.<br><br>"; 

    include("include/view_active.php"); 

    ?> 


    </td></tr> 
    </table> 


    </body> 
    </html>
    login section on my site [this is the design & layout of my login section]
    PHP:
    <!--Login Background Starts --> 
    <
    div id="login-bg"
                <!--
    Login Area Starts --> 
                <
    div id="login-area"
                    <
    form action="process.php" method="post" name="Login" id="Login"
                        <
    label>Members Login:</label
                        <
    div align="center"
                          <
    input name="user" type="text" id="user" value="username" maxlength="32" /> 
                          <
    input name="pass" type="password" id="pass" value="password" maxlength="32" /> 
                          <
    input name="Submit" type="submit"  class="login-btn" title="Login" value="Login" src="images/login-btn.gif" alt="Login" /> 
                          <
    br class="spacer" /> 
                      <
    span class="style1">  Remember Me | <a href="forgotpass.php">Forgot Password?</a></span></div
                  </
    form
                </
    div
                <!--
    Login Area Ends --> 
            </
    div
            <!--
    Login Background Ends --> 
    Also i recommend viewing this link [http://cykstudios.exofire.net/] as well, its my header and what i want the design to look like.

    if you dont understand what i am asking for, i want the first code to be integrated [combined] with the second code.


    Any help at all is very much appreciated!!!
     
  2. Submariner

    Submariner New Member

    Messages:
    44
    Likes Received:
    1
    Trophy Points:
    0
    Looks like all you need to do is put the second code block in the else clause of the first. Then if the user is not logged in the second block will be displayed and if the user is logged in the upper section of the if will be displayed.

    Have fun...
    James
     
  3. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    I forgot to mention that I suck at php coding. I understand what your saying, but I don't know how to write/add code blocks. I am new to php coding soo..... Could you help a little bit more?
     
    Last edited: Jul 18, 2009
  4. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    Ok.. I can do this but I'm sorta confused on what you want.. You want the PHP code integrated with the site?
     
  5. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    if you go to my site [CYK Studios] you see on the top right corner my members login section, this is the second box of code i posted earlier. i want the first box of code combined with the second box of code so i can then copy and paste it into my login section through Dreamweaver. yes it will combine with my page, but ill clone the code later so that it works on multiple pages. Right now i just want the two boxes of codes merged. You're basically doing an organ transplant, you're taking out the junk code that doesn't connect me to the server [from the second code box] and replacing it with the first box of code that does connect me to the server.

    i kinda have a hard time explaining myself so please tell me if im just babbling on about nothing...

    Also please take note that when your viewing my site, the sign up button is not with the other member login section. i will supply you with that code right here.

    Code:
    <!--Navigation Background Part Starts -->
    <div id="navigation-bg">
    	<!--Navigation Part Starts -->
    	<div id="navigation">
    		<ul class="mainMenu">
    			<li><a href="index.html" class="selectMenu">Home</a></li>
    			<li><a href="videos.html">Videos</a></li>
    		  <li><a href="archives.html">Archives</a></li>
    		  <li><a href="http://cykstudios.exofire.net/phpBB3/index.php" target="_parent">Forums</a></li>
    		  <li><a href="podcasts.html">Podcasts</a></li>
    		  <li><a href="downloads.html">Downloads</a></li>
    		  <li class="noBg"><a href="contactus.html">Contact Us</a></li>
    	  </ul>
    		<a href="register.php" class="signup"></a>
    	  <br class="spacer" />
    		<ul class="subNav">
    			<li class="noBg"></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    	  </ul>
    		<br class="spacer" />
    	</div>
    	<!--Navigation Part Ends -->
    </div>
    <!--Navigation Background Part Ends -->
    
    this part here "<a href="register.php" class="signup"></a>" that's the sign up button in the code. if you didnt notice i gave you my entire navbar code to hopefully help you more...

    I thank you soo much for helping me with this. Once again i am not a good PHP coder when it comes to this, and this login system if my first project! so it's kinda stressful trying to look for help and getting crap for answers. But everyone here has helped alot...

    I thank you once again...
     
  6. Chrisisrad

    Chrisisrad New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Let me see if ive got this right, you want to style your login, to look like your site?
    And only show content to users that are signed up?
     
  7. xav0989

    xav0989 Community Public Relation Community Support

    Messages:
    4,467
    Likes Received:
    95
    Trophy Points:
    0
    first of all, you should seriously think of going through a php tutorial if you plan on building yourself your website. Help on the forums is nice, but it may take days to accomplish what you can do in minutes with the right knowledge. I recommend 2 tutorials.

    First one is at w3schools. W3schools is a great resource for any web developer. It's usually the goto place right after the official docs and just before google. There is tons of ressources on this website.
    The other website tutorial I recommend is on Tizag. Tizag is another type of tutorial and provides more hads-on examples. With those two in mind, you should be good for php.
    Always remember that you can use the official php doc for reference.

    Now concerning your php problem. If you want, I can edit your files for you. Simply create a FTP user for me and PM me the info. I will get my hands dirty in the code and I will make your login section work.
     
    Last edited: Jul 19, 2009
  8. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    Answer: Yes!!!, I really can't explain myself that well, but that's what i'm after. YES! :lol:

    When i do look to Google for PHP help i do see W3Schools alot but i never went cause no one else whom i asked said anything about them when i asked for a good tutorial, they just told me to stay on the forums and ask for help.

    I will check out both of these tutorials, thank you.


    Now about my PHP problem, i want to wait before i give you access to see what the other two users that posted here can do, cause i'm very cautious when it comes to giving helping strangers my site info [besides my site address].i just want to wait first, before i go straight to you for the problem, nothing personal, it's just internet saftey... :hahano:
     
  9. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    This can be a little complicated when you think about it.. Since you cannot have .html files executing php code.. you would need to change them to .php.. HTML is horrible since you have to update the header file on every page.. A good idea is to make a header.php file and a footer.php file and just move the header and footer there and include them into every php file..
     
  10. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    Okay, what all would i include in my header/footer.php? i know their separate pages, but for my header.php should i have everything up to my navbar or just the header and login system?
     
  11. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    header.php would have:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>CYK Studios | Home</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    .style1 {
    	color: #FCF7CC;
    	font-weight: bold;
    	font-size: x-small;
    }
    .style2 {color: #4B1A15}
    -->
    </style>
    </head>
    
    <body>
    <!--Header Background Part Starts -->
    <div id="header-bg">
    	<!--Header Contant Part Starts -->
    	<div id="header">
    		<a href="index.html" target="_parent"><img src="http://forums.x10hosting.com/images/logo.gif" alt="CYK Studios" name="logo" width="281" height="62" class="logo" id="logo" title="CYK Studios" /></a>
    		<!--Login Background Starts -->
    <div id="login-bg">
    			<!--Login Area Starts -->
    			<div id="login-area">
    <?php
    if($session->logged_in){  
       echo "<h1>Logged In</h1>";  
       echo "Welcome <b>$session->username</b> <br><br>"  
           ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"  
           ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";  
       if($session->isAdmin()){  
          echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";  
       }  
       echo "[<a href=\"process.php\">Logout</a>]";  
    }  
    else{
    ?>
    				<form action="process.php" method="post" name="Login" id="Login">
    					<label>Members Login:</label>
    					<div align="center">
    					  <input name="user" type="text" id="user" value="username" maxlength="32" />
    					  <input name="pass" type="password" id="pass" value="password" maxlength="32" />
    					  <input name="Submit" type="submit"  class="login-btn" title="Login" value="Login" src="http://forums.x10hosting.com/images/login-btn.gif" alt="Login" />
    					  <br class="spacer" />
    				  <span class="style1">  Remember Me | <a href="forgotpass.php">Forgot Password?</a></span></div>
    			  </form>
    <?php } ?>
    			</div>
    			<!--Login Area Ends -->
    		</div>
    		<!--Login Background Ends -->
    		<br class="spacer" />
    	</div>
      <!--Header Contant Part Ends -->
    </div>
    <!--Header Background Part Ends -->
    <!--Navigation Background Part Starts -->
    <div id="navigation-bg">
    	<!--Navigation Part Starts -->
    	<div id="navigation">
    		<ul class="mainMenu">
    			<li><a href="index.html" class="selectMenu">Home</a></li>
    			<li><a href="videos.html">Videos</a></li>
    		  <li><a href="archives.html">Archives</a></li>
    		  <li><a href="http://cykstudios.exofire.net/phpBB3/index.php" target="_parent">Forums</a></li>
    		  <li><a href="podcasts.html">Podcasts</a></li>
    		  <li><a href="downloads.html">Downloads</a></li>
    		  <li class="noBg"><a href="contactus.html">Contact Us</a></li>
    	  </ul>
    		<?php if(!$session->logged_in){ echo '<a href="register.php" class="signup"></a>'; } ?>
    	  <br class="spacer" />
    		<ul class="subNav">
    			<li class="noBg"></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    		  <li></li>
    	  </ul>
    		<br class="spacer" />
    	</div>
    	<!--Navigation Part Ends -->
    </div>
    <!--Navigation Background Part Ends -->
    
    footer.php would have:

    Code:
    <!--Footer Part Starts -->
    <div id="footer-bg">
    	<!--Footer Menu Part Starts -->
    	<div id="footer-menu">
    		<ul class="footMenu">
    			<li class="noDivider"><a href="index.html">Home</a></li>
    		  <li><a href="#">About</a></li>
    			<li><a href="#">Support</a></li>
    			<li><a href="#">Site Map</a></li>
    			<li><a href="contactus.html">Contact</a></li>
    	  </ul>
      <br class="spacer" />
    		<p class="copyright">Copyright &copy; CYK Studios 2009 All Rights Reserved</p>
    		<p class="copyright topPad">Powered by <a href="http://www.templatekingdom.com/tkp/35/" target="_parent">TemplateKingdom.com</a> | <a href="http://www.x10hosting.com" target="_parent">X10 Hosting</a></p>
      </div>
    	<!--Footer Menu Part Ends -->
    </div>
    <!--Footer Part Ends -->
    </body>
    </html>
    
    Edit:
    Don't forget that you also need to edit process.php, register.php, forgotpass.php, and any other pages into your template and that you may need to edit the Logged In formatting..

    Edit2: If you don't feel like doing all the edit's yourself, feel free to PM me FTP info.. (Not the main FTP info.. Make an extra FTP account in cPanel)
     
    Last edited: Jul 19, 2009
  12. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    I'll take a whack at it cause but I will pm you to check my work. Thanks...
     
  13. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    Off Topic: Nice spelling on Community.. [​IMG]
     
  14. nirajkum

    nirajkum New Member

    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    0
    make header footer code nav code in seperate file ... make one index.php and include it in the file ...
     
  15. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    Whoops! I'll fix that spelling error...
    —————————————————————

    should I make the page [index.php] or [main.php] cause that will alter a lot of stuff if I have one or the other. My login php script I have is main.php. So what would the safe route be?
     
  16. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    the main page of your site has to be index.php instead of index.html.. It's a quick switchover if you know what your doing..
     
    Last edited: Jul 19, 2009
  17. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    Whoops! I'll fix that spelling error...
    —————————————————————

    should I make the page [index.php] or [main.php] cause that will alter a lot of stuff if I have one or the other. My login php script I have is main.php. So what would the safe route be?
     
  18. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    nice doublepost..

    Let me quote myself..
     
    Last edited: Jul 19, 2009
  19. rufussweetwater

    rufussweetwater New Member

    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    0
    sorry, i was away from my computer and was posting on my iTouch... ill get right on that coding and name changing...
     
  20. zapzack

    zapzack New Member

    Messages:
    606
    Likes Received:
    19
    Trophy Points:
    0
    Check your PM's for my reply. It seems you didn't place my user in the correct directory..
     

Share This Page