Hi all, most likely a basic question but i know nothing when it comes to php.

Basically i have all my php files and database set up for my login and registration but i am at a loss on how to incluse it into my html website.

I have tried doiing as suggested and added the code to the head of my pages with no joy

Recommended Answers

All 5 Replies

Member Avatar for diafol

Unless you show your code, it's difficult to know how to help you.

Hi all, most likely a basic question but i know nothing when it comes to php.

How did you get all your php files??

Sorry, should have included everything, code came from hotscripts.com and is in the following files

Config.php

<?php
/*
This script was downloaded at:
LightPHPScripts.com
Please support us by visiting
out website and letting people
know of it.
Produced under: LGPL
*/

/* Main Options */
//----------------

/* Which page user goes to after logoss */
$logoutPage = 'login.php';

/* Secure page to redirect to after login */
$loginPage = 'myaccount.php';

/* Start session? Set this to false, if
you are already starting the session elsewhere
*/
$startSession = TRUE;

/* Use Cookies with sessions*/
$useCookies = TRUE;

/* Stay loged in for? -> cookies */
/* in seconds:
3600 ->  1 hr, 86400 -> 1 day
604800 -> 1 week, 2419200 -> 1 month
29030400 -> 1 year
*/
$logedInFor = 2419200;

/* Domain name -> cookies */
$domainName = 'example.com';

/*
Notes: Please note that using sessions,
will store a cookie with the ID on userside.
To make this work for users without cookies,
propagate the ID through the URLS
in this manner: 
nextpage.php?<?php echo htmlspecialchars(SID); ?>
*/

/* Connect to database? Set to false, if you
are already conneted */
$connectDatabase = TRUE;

/* Database Info */
$databaseUserName = 'name';
$databaseUserPassword = 'pass';
$databaseHostName = 'localhost';
$databaseName = 'db';

/* Table Info */
$tableName = 'userlist';
$userNameField = 'userName';
$userPasswordField = 'UserPassword';

/** SEC 334 **/
?>

Register.php

<?php
/*
This script was downloaded at:
LightPHPScripts.com
Please support us by visiting
out website and letting people
know of it.
Produced under: LGPL
*/

/* Start session */
if($startSession == TRUE){ session_start();}

/* Config file */
include('config.php');

/* Check for submition */
if($_POST['submitID'] == 2){

    /* Connect to database & query */
    if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}

    /* sanitize and check info */
    $userName = mysql_real_escape_string($_POST['userName'],$dbc);
    $password = mysql_real_escape_string($_POST['password'],$dbc);

    if($userName == NULL) { $message = 'Please enter username.';}
    if($message == NULL && $password == NULL){ $message = 'Please enter password.';}
    if($message == NULL && $password != $_POST['password2']){ $message = 'Passwords do not match.';}

    if($message == NULL)
    {       
        $userQuery = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM `$tableName`
         WHERE `$userNameField`='$userName'"));
        if($userQuery[0] > 0){
            $message = 'This username already exists. Please select another.';          
        } else {
            /* Add user */
            $addUser = mysql_query("INSERT INTO `$tableName` (`$userNameField`,`$userPasswordField`) 
                VALUES ('$userName','$password')");
            if($addUser)
            {
                /* Disconnect from database */
                if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}

                /* Log use in */
                $_SESSION['isLoged'] = 'yes';
                $_SESSION['userName'] = $userName;
                /* add cookies ?*/
                /* expire in 1 hour */
                if($useCookies == TRUE)
                {
                    setcookie("isLoged", 'yes', time()+logedInFor, "/", ".$domainName", 1);
                    setcookie("userName", $userName, time()+logedInFor, "/", ".$domainName", 1);
                }

                /* Redirect to login page */
                header("Location: $loginPage");
                exit();
            } else {
                $message = 'Internal error. Please contact administrator.';
            }
        }       
    }
    /* Disconnect from database */
    if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}
}
?>
<!--
/*
This script was downloaded at:
LightPHPScripts.com
Please support us by visiting
out website and letting people
know of it.
Produced under: LGPL
*/
-->
<?php

/* Display error messages */
if($message != NULL){?>
<table width="100%"  border="0" cellpadding="3" cellspacing="0" bgcolor="#FFCCCC">
  <tr>
    <td><div align="center"><strong><font color="#FF0000"><?=$message;?></font></strong></div></td>
  </tr>
</table>
<?php } ?>
<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" name="register" id="register" style="display:inline;">
  <table width="100%" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#99CC33">
    <tr bgcolor="#99CC99"> 
      <td colspan="2"><div align="center"><strong>Please enter registration information: </strong></div></td>
    </tr>
    <tr> 
      <td width="47%"><strong>Username:</strong></td>
      <td width="53%"><input name="userName" type="text" id="userName"></td>
    </tr>
    <tr> 
      <td><strong>Password:</strong></td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr>
      <td><strong>Re-enter password: </strong></td>
      <td><input name="password2" type="password" id="password2" /></td>
    </tr>
    <tr> 
      <td colspan="2"><div align="center"><font face="Georgia, Times New Roman, Times, serif"><strong>
          <input name="Submit" type="submit" id="Submit" value="Register">
          <input name="submitID" type="hidden" id="submitID" value="2">
</strong></font> </div></td>
    </tr>
    <tr>
      <td colspan="2"><div align="right"><a href="http://lightphpscripts.com" target="_blank"><font size="1">Powered by LPS</font></a> </div></td>
    </tr>
  </table>
</form>

Login.php

<?php

/* Start session */
if($startSession == TRUE){ session_start();}

/* Config file */
include('config.php');

/* Check for submition */
if($_POST['submitID'] == 1){

    /* Connect to database */
    if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}

    /* sanitize and check info */
    $userName = mysql_real_escape_string($_POST['userName'],$dbc);
    $password = mysql_real_escape_string($_POST['password'],$dbc);

    if($userName == NULL) { $message = 'Please enter username.';}
    if($message == NULL && $password == NULL){ $message = 'Please enter password.';}

    if($message == NULL)
    {               
        $userQuery = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM " . $tableName .
        " WHERE `" . $userNameField . "`='$userName' AND `" . $userPasswordField . "`='$password'"));       

        /* If usercount is more than 0 -> ok */
        if($userQuery[0] > 0){
            /* Disconnect from database */
            if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}

            $_SESSION['isLoged'] = 'yes';
            $_SESSION['userName'] = $userName;

            /* add cookies ?*/
            /* expire in 1 hour */
            if($useCookies == TRUE)
            {
                setcookie("isLoged", 'yes', time()+logedInFor, "/", ".$domainName", 1);
                setcookie("userName", $userName, time()+logedInFor, "/", ".$domainName", 1);
            }

            /* Redirect to login page */
            header("Location: $loginPage");
            exit();
        } else {
            $message = 'Invalid username and/or password!';
        }
    }
    /* Disconnect from database */
    if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}
}
?>
<!--
-->
<?php

/* Display error messages */
if($message != NULL){?>
<table width="100%"  border="0" cellpadding="3" cellspacing="0" bgcolor="#FFCCCC">
  <tr>
    <td><div align="center"><strong><font color="#FF0000"><?=$message;?></font></strong></div></td>
  </tr>
</table>
<?php } ?>
<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" name="login" id="login" style="display:inline;">
  <table width="100%" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#99CC33">
    <tr bgcolor="#99CC99"> 
      <td colspan="2"><div align="center"><strong>Please log in:</strong></div></td>
    </tr>
    <tr> 
      <td width="47%"><strong>Username:</strong></td>
      <td width="53%"><input name="userName" type="text" id="userName"></td>
    </tr>
    <tr> 
      <td><strong>Password:</strong></td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr> 
      <td colspan="2"><div align="center"><font face="Georgia, Times New Roman, Times, serif"><strong>
          <input name="Submit" type="submit" id="Submit" value="Sign-In">
          <input name="submitID" type="hidden" id="submitID" value="1">
</strong></font> </div></td>
    </tr>
    <tr>
      <td colspan="2"><div align="right"><a href="http://lightphpscripts.com" target="_blank"><font size="1">Powered by LPS</font></a></div></td>
    </tr>
  </table>
</form>

Instructions

Step 1

Open config.php, fill it with the correct information

Step 2

Place the registration file where you want it to appear as:

<?php include('register.php'); ?>
Step 3

Place login.php in the page where you want the login box to appear as:

<?php include('login.php'); ?>
Step 4

To log out a user, redirect them to logoff.php as:

http://example.com/logoff.php
Step 5

To protect any pages, place this code on top most of the page:

<?php

session_start();

if($_SESSION['isLoged'] != 'yes' || $_SESSION['userName'] == NULL)

    header("Location: login.php");exit();

?>
Step 6

To protect any directory, place the above code in a file called index.php and
place that file in the directory.**

Thanks for any help

Cheers

Member Avatar for Zagga

If you are adding any PHP code (as per instructions) to a HTML page, you must change the extension from .html to .php.
For example, index.html must be saved as index.php
You only need to do this with pages you add the login box to, and any 'protected' pages.

Expanding on what @Zagga said, you can also set up your server to read .html files as PHP. You will need to set up a .htaccess file to do this.

Place an .htaccess file in the root of your application with the following:

AddType application/x-httpd-php .html

Member Avatar for diafol

OK, I see. You just want to drop in some code and away you go?

Zagga's suggestion should do it. However, this is a bit dangerous - if you don't learn the basics of php, the script could be totally useless when it doesn't work as expected. Sure you can drive a car when you don't understand how it works - and you can take it to a mechanic if it breaks. A script on the other hand, can't usually be handed off to a programmer - well it can if you want to pay for the services, but you're likely to be left with asking for advice from forums like this, who will help you solve the problem yourself! So, learning php (at least the basics), should be of major benefit to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.