Solved

Add php log-in script to html page.

Posted on 2012-12-27
17
428 Views
Last Modified: 2013-11-26
Hi,

I am working with a html website template that came with fields for user name and password. I have a working php script that user logs into to access restricted pages. My question to you guys,  how can I  make it so that existing html user name and passwords be entered on my html page instead of having to direct the user to php page?

Sample html page is at shawunaa.com/test

php pages is shawunaa.com/membership/index.php

Thanks
0
Comment
Question by:KLM56
  • 5
  • 3
  • 3
  • +2
17 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 38725672
That's a bit confusing.  You can have the original form on an HTML page but the 'action' has to be the PHP page.  In addition, every other page that is being 'protected' by the login must be PHP so you can check the login every time someone accesses the page.
0
 

Author Comment

by:KLM56
ID: 38725704
I know it must be confusing, cause I don't even know what I am doing. When you say the action must be the php page. Can you explain for a new be? I read somewhere, that I can add some php script to the html page, but I have to research that some more.

Thanks for your response.
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 125 total points
ID: 38725734
PHP is a programming language that can be used to put data in a database and check it so you can know if it is a valid login.  HTML is Only a page description language.  You use it to put up a page but it can't be used to access a database or check anything.

At this point, I have to say this login project is beyond you at the moment.  PHP.net has tutorials http://php.net/manual/en/tutorial.php as does W3Schools http://www.w3schools.com/php/default.asp  .  It will take quite a while for you to learn enough to complete this project.  This book, PHP & MySQL: Novice to Ninja, http://www.sitepoint.com/books/phpmysql5/ is also frequently recommended.
0
 

Author Comment

by:KLM56
ID: 38725741
OK, Thank you....I will do some more research on this.
0
 
LVL 9

Assisted Solution

by:rinfo
rinfo earned 125 total points
ID: 38726480
You most certainly need a script page for database connectivity if you have a user database which could be a database server, text file or xml file .
Option for script could be a php or javascript.
A simple example using php is
http://www.html-form-guide.com/php-form/php-login-form.html
where as if you wants to use javascript
http://www.daniweb.com/web-development/javascript-dhtml-ajax/code/330933/a-simple-html-login-page-using-javascript
0
 

Author Comment

by:KLM56
ID: 38726535
Thanks rinfo...

The login php script works fine, I just can't figure how to use my main login as the user input. I will look at your examples and see if it gets me closer. Do appreciate the help.
0
 
LVL 9

Expert Comment

by:rinfo
ID: 38726546
I have checked your source code .

you just need to put name of your php script which verified login here
<form method="post" action="">
this line should be changed to
<form method="post" action="your php script file name">
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 38726759
This article is my teaching example that shows all the essential moving parts.  Have a read and let me know if you have any questions.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

Going forward in your web experience, just "forget" about HTML pages and think "100% PHP" forever.  PHP is a server-side language that generates HTML.  If you're smart about it, you will write much less HTML and much more PHP because PHP promotes reuse of data objects, including HTML documents.  For your existing HTML pages, you can add the PHP capability by simply parsing HTML documents through PHP.  The parser will ignore anything that is not captioned with <?php start tag, and if you want to add PHP at any time, the parser will use the PHP instructions.

Here is a sample of a web page showing how PHP can make your coding more efficient.
http://www.landonbaseball.com/basic.php
The entire PHP document is here:
<?php // landonbaseball.com/basic.php
require_once('_config.php');
require_once('_header.php');

echo '<p>Hello World</p>' . PHP_EOL;

require_once('_footer.php');

Open in new window

A good book to help you get a foundation:
http://www.sitepoint.com/books/phpmysql5/

Best regards, and welcome to PHP, ~Ray
0
 

Author Comment

by:KLM56
ID: 38727823
Thank you guys. This is so much to take in at once, but I want to learn it, so I will read up on all provided information.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38728150
Here are the technologies you will want to master:

Client side:
HTML (5)
CSS (3)
JavaScript, especially jQuery

Server side:
PHP
MySQLi or PDO

If you like technical books, search Amazon.com for those topics.  Techies are great about reviewing books, so if you find books with lots of positive reviews, those are the ones to go for!
0
 

Author Comment

by:KLM56
ID: 38728250
Guys any suggestion for converting the existing website to php? Is there a program that would convert all the existing pages to php. Would I have to manually go into each folder and change if file within the website?

Thanks
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 38728449
I would not suggest converting your site to PHP until you had learned at least the basics.  Of course, the Very first step is to back up your current site, burn it to a CD and save it... just in case.
0
 
LVL 9

Expert Comment

by:rinfo
ID: 38728543
There is no one click solution for converting an html site to php.
0
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 125 total points
ID: 38729644
greetings KLM56 , , as said already, you really should take some time and learn the basics of PHP, not just reading about it, but doing very many "Test" scripts (php files on your server), this is particularly important for the database access in PHP code. Setting up database tables with useful and proper columns (fields) and then use INSERT, SELECT and UPDATE  SQL statements to change and get info on database will not happen in a few days of study. But there are hundreds of PHP tutorial web sites and pages available. One of  a php developer's greatest help is learning how to google (yahoo, bing) search for the code examples that you need for a particular project, there's not much in PHP development that has NOT been done already many times.


Maybe this can help you, some "for real" MySQLi (improved) code, many times most of the "Old" MySQL coders do not understand the new coding setups of the Improved version.
$mysqli = new mysqli('localhost', 'user', 'passw', 'DB_name');
	if (!mysqli_connect_errno()) {
		$query = 'INSERT INTO coolo (name1, user1, asoc1, belong2, noton1) VALUES (?,?,?,?,?)';
// IMPORTANT use PREPARE for ALL user input (From POST or GET)
		$stmt = $mysqli->prepare($query);
// execute will READ the REALTIME values of the bind_param variables when execute is called
		$fname = 'Loco Menendez';
		$uname = 'Loco';
// Comma-separated values  CSV data
		$asoc1 = 'TVA,NRA,CCA,DDT,GDC,USA';
		$belong = 533;
		$ton1 = 'DDT';
// IMPORTANT, you MUST Bind the Variables to the the $stmt
		$stmt->bind_param("sssis", $fname, $uname, $asoc1, $belong, $ton1);
		if(!$stmt->execute()) echo 'execute has failed<br>'; else echo 'Rows Inserted '.$stmt->affected_rows.'<br>';
// You can Call $stmt->execute() as many times as you need, just CHANGE the variables for different inserts
		$fname = 'fuffy pink';
		$uname = 'pinky';
		$asoc1 = 'OOH,WOW,HOW,PRE,TTY';
		$belong = 121;
		$ton1 = 'HAT';
// this execute will read the NEW values of the BIND variables
// this is NOT at all like the OLD MySQL function calls
		if(!$stmt->execute()) echo 'execute has failed<br>'; else echo 'Rows Inserted '.$stmt->affected_rows.'<br>';
		$stmt->close();
	echo '<br>Stats : '.$mysqli->stat().'<br>server info : '.$mysqli->server_info.'<br><br>';

// use $mysqli->query just like the OLD MySQL code setups, But it does NOT offer any improved security
	if ($result = $mysqli->query('SELECT * FROM coolo')) {echo 'Number returned rows: '.$result->num_rows.'<br>';
		while ($row = $result->fetch_object()) {echo 'ID: '.$row->id.' user1 '.$row->user1.' name1 '.$row->name1.' asoc1 '.
			$row->asoc1.' belong2 '.$row->belong2.' noton1 '.$row->noton1.'<br>'; 
		}
		mysqli_free_result($result);
		} else echo $mysqli->error;
	$mysqli->close();
	} else echo '<b>BIG mysqli ERROR - did NOT create the mysqli Object '.mysqli_connect_error().'</b>';

Open in new window


you might do well to learn the improved mysqli instead of MySQL or the "wrapper" PDO stuff.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38734499
...suggestion for converting the existing website to php
This is like converting a bushel of apples into an apple pie -- there are a lot of steps and processes.  But at its simplest, you probably want to make the HTML documents into "units" of the page that can be rendered by PHP.  That means copying the HTML into PHP string variables and using echo to write the strings to the browser output stream.  You can do this best by breaking the HTML up into smaller files and reading the files from the server.  Templating scripts do this sort of thing in all the major frameworks and CMS systems.

I were just starting on this journey, I would start here:
http://www.sitepoint.com/books/phpmysql5/
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now