• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

Add php log-in script to html page.

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
KLM56
Asked:
KLM56
  • 5
  • 3
  • 3
  • +2
4 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
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
 
KLM56Author Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
KLM56Author Commented:
OK, Thank you....I will do some more research on this.
0
 
rinfoCommented:
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
 
KLM56Author Commented:
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
 
rinfoCommented:
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
 
Ray PaseurCommented:
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
 
KLM56Author Commented:
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
 
Ray PaseurCommented:
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
 
KLM56Author Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
rinfoCommented:
There is no one click solution for converting an html site to php.
0
 
Slick812Commented:
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
 
Ray PaseurCommented:
...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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 5
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now