I need some help with PHP, SQL and HTML
#1
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
I need some help with PHP, SQL and HTML
Afternoon all,
I'm attempting to learn a bit more about PHP, SQL (specifically mySQL) and HTML.
I know a bit about HTML, as I've coded websites. I know what PHP is, and the same is true of SQL, but I'm only just delving into how to use them.
I've looked at some examples and have worked out how to write PHP code to create a table in a mysql database and also how create a record in that table and also how to read the contents of that record back.
It all seems somewhat straightforward, which is good. So I'm plodding along and trying various things out.
So what is it that I need help with? Ok, here goes (I think we're probably talking about running very very quickly before learning how to use ones legs ):
I want to try and re-write a login system in PHP. The current setup uses a cgi, which is a Mac application, written for pre OS X systems. Thus I can't just port things over to OS X or any *nix system.
The way the system currently works is that someone submits a form which sends an email with their username and email address (and possibly other bits of information) and these are manually checked to make sure the person is real and it's not some bot.
Using this information, I run a script which has an interface that allows me to input this information, plus it allows me to generate a password, and set various options, which are boolean in nature (has access to ABC, has access to XYZ, etc...). This will then create a file in a folder. The name of the file is the user's name, and the contents of the file are the email address, password, and the other boolean options. An email is then sent to the user with their login information.
They will then go to a page on a website, which calls the cgi, this prompts for the name and password, and it will then scan the folder structure to see if there is a file with the name entered, if a match is found, it reads the file, grabs the password, checks that against the input and if it's valid the user is logged in and a new page is displayed.
The cgi is also being clever about this page. It's reading the page (it's got a different extension, and the server's mime type has been configured to use the cgi if a page with this extension is loaded) and looking for various tags in the file, for example:
The cgi compares the values it's read from the file on login against these tags. Thus if the "has access to ABC" value is true (actually it's 1 or 0, so in this case if it's 1) then the html data within that tag is displayed, and if the value is false, the data is not displayed.
Phew. Still with me?
So far I've got my database setup, I can add users to it, and read them back, and I'm just reading about how to create login sessions and it seems that this side of things should be pretty easy. The bit I'm wondering about is the second portion, the reading of the html like file (it is just HTML but with a different extension and those special tags).
I know I can perform conditional checking in the php section of the file, so I can get the "has access to ABC" value from the database and check if it's 1 or 0. However, I'm trying to figure out if I'd need to have HTML code within the PHP section of the page, or wether I can have it after that?
I've messed around a little with vBulletin, and know that they have, in HTML, conditional checking lines such as:
I'm unsure as to wether this is something special that vB handles, as in it's got some class or something somewhere that knows what to do when it comes across the <if condition> lines in html. To me it seems that this would be perfect, as I could do a search and replace in the current files for the «StartShow ABC» and «EndShow ABC» lines and replace them with the conditional if statements.
Hmm, thinking about it, I guess I could just do that anyway, replacing them with php "if" statements and moving the stuff inside a php block.
Any advice or suggestions greatly welcomed.
I'm attempting to learn a bit more about PHP, SQL (specifically mySQL) and HTML.
I know a bit about HTML, as I've coded websites. I know what PHP is, and the same is true of SQL, but I'm only just delving into how to use them.
I've looked at some examples and have worked out how to write PHP code to create a table in a mysql database and also how create a record in that table and also how to read the contents of that record back.
It all seems somewhat straightforward, which is good. So I'm plodding along and trying various things out.
So what is it that I need help with? Ok, here goes (I think we're probably talking about running very very quickly before learning how to use ones legs ):
I want to try and re-write a login system in PHP. The current setup uses a cgi, which is a Mac application, written for pre OS X systems. Thus I can't just port things over to OS X or any *nix system.
The way the system currently works is that someone submits a form which sends an email with their username and email address (and possibly other bits of information) and these are manually checked to make sure the person is real and it's not some bot.
Using this information, I run a script which has an interface that allows me to input this information, plus it allows me to generate a password, and set various options, which are boolean in nature (has access to ABC, has access to XYZ, etc...). This will then create a file in a folder. The name of the file is the user's name, and the contents of the file are the email address, password, and the other boolean options. An email is then sent to the user with their login information.
They will then go to a page on a website, which calls the cgi, this prompts for the name and password, and it will then scan the folder structure to see if there is a file with the name entered, if a match is found, it reads the file, grabs the password, checks that against the input and if it's valid the user is logged in and a new page is displayed.
The cgi is also being clever about this page. It's reading the page (it's got a different extension, and the server's mime type has been configured to use the cgi if a page with this extension is loaded) and looking for various tags in the file, for example:
Code:
«StartShow ABC» Show this data if the user has ABC access «EndShow ABC» «StartShow XYZ» Show this data if the user has ABC access «EndShow XYZ»
Phew. Still with me?
So far I've got my database setup, I can add users to it, and read them back, and I'm just reading about how to create login sessions and it seems that this side of things should be pretty easy. The bit I'm wondering about is the second portion, the reading of the html like file (it is just HTML but with a different extension and those special tags).
I know I can perform conditional checking in the php section of the file, so I can get the "has access to ABC" value from the database and check if it's 1 or 0. However, I'm trying to figure out if I'd need to have HTML code within the PHP section of the page, or wether I can have it after that?
I've messed around a little with vBulletin, and know that they have, in HTML, conditional checking lines such as:
Code:
<if condition="$show['pmlink']"> <tr><td class="vbmenu_option"><a href="private.php?$session[sessionurl]do=newpm&u=$post[userid]" rel="nofollow"><phrase 1="$post[username]">$vbphrase[send_private_message_to_x]</phrase></a></td></tr> </if>
Hmm, thinking about it, I guess I could just do that anyway, replacing them with php "if" statements and moving the stuff inside a php block.
Any advice or suggestions greatly welcomed.
Last edited by Markus; 05 March 2009 at 04:40 PM.
#2
Scooby Regular
Join Date: Apr 1999
Location: Bore Knee Muff
Posts: 3,666
Likes: 0
Received 0 Likes
on
0 Posts
Not had time to digest all that Marcus but phpmyadmin runs under MAMP (or any php/mysql installation) and is very good.
You can run queries, create databases and tables and it will show you the php code to do it...
You can run queries, create databases and tables and it will show you the php code to do it...
#3
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
Hi Rich,
One step ahead of you I've had phpmyadmin installed for a while, but only ever used it to export and import databases. I've basically done what you suggest and watched the commands that get issued to create/modify/delete tables/records, and am learning how to put those commands into php.
I've setup a test page, replacing the «StartShow» tags with:
It does work, but I'm not completely happy about using the print command with multiple lines of html, as I'll have to start escaping characters.
One step ahead of you I've had phpmyadmin installed for a while, but only ever used it to export and import databases. I've basically done what you suggest and watched the commands that get issued to create/modify/delete tables/records, and am learning how to put those commands into php.
I've setup a test page, replacing the «StartShow» tags with:
Code:
<?php if ($ShowABC == "1") { print "<p>This is displayed if I have ABC access</p><br>"; } ?>
#4
Scooby Regular
Join Date: Apr 1999
Location: Bore Knee Muff
Posts: 3,666
Likes: 0
Received 0 Likes
on
0 Posts
You end the php tag and then follow on with html, then just open a php tag again and close the braces.
<?php if ($ShowABC=="1") { ?>
<p>blah</p>
<h1>a title</h1>
<img src="" title="" />
<?php } ?>
<?php if ($ShowABC=="1") { ?>
<p>blah</p>
<h1>a title</h1>
<img src="" title="" />
<?php } ?>
#5
Scooby Regular
Join Date: Apr 1999
Location: Bore Knee Muff
Posts: 3,666
Likes: 0
Received 0 Likes
on
0 Posts
I always use
echo 'some text';
as well, not sure which is best to be honest lol.
If you use double quotes you can use variables within the string ala
echo "print this $variable and then $another variable";
where as with single quotes you would do
echo 'print this'.$variable.' and then '.$another.' variable';
Also you could pout common html into there own php files and include them.
include 'commonhtml.php';
Better still start looking into object based programming and use methods...
I build all our sites in php/mysql...
echo 'some text';
as well, not sure which is best to be honest lol.
If you use double quotes you can use variables within the string ala
echo "print this $variable and then $another variable";
where as with single quotes you would do
echo 'print this'.$variable.' and then '.$another.' variable';
Also you could pout common html into there own php files and include them.
include 'commonhtml.php';
Better still start looking into object based programming and use methods...
I build all our sites in php/mysql...
#6
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
Ah ha! That makes sense and is exactly what I'd want to do, so I'll give that a shot.
I always use
echo 'some text';
as well, not sure which is best to be honest lol.
If you use double quotes you can use variables within the string ala
echo "print this $variable and then $another variable";
where as with single quotes you would do
echo 'print this'.$variable.' and then '.$another.' variable';
Also you could pout common html into there own php files and include them.
include 'commonhtml.php';
Better still start looking into object based programming and use methods...
I build all our sites in php/mysql...
echo 'some text';
as well, not sure which is best to be honest lol.
If you use double quotes you can use variables within the string ala
echo "print this $variable and then $another variable";
where as with single quotes you would do
echo 'print this'.$variable.' and then '.$another.' variable';
Also you could pout common html into there own php files and include them.
include 'commonhtml.php';
Better still start looking into object based programming and use methods...
I build all our sites in php/mysql...
I was considering converting the whole site to something like Joomla, that does have a login system, however, their ACL stuff is very limited, unless I pay for the, umm, think it's BEYOS jACL product, which then, I think, as it's been a while since I used it, the ability to define my own groups, at which point I could give the level of access I want.
Unless I'm missing something and it is possible to configure multiple groups and have users present in multiple groups and set viewing permissions based on those group assignments.
Trending Topics
#8
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
Ok, another bozo moment here.
I want to compare two items, they will be text strings and one will, eventually, be the input from a form.
It's basically a username and password submittal form. I want the user name to be case insensitive, but the password, obviously to be case sensitive.
I *think* the password bit is easy, because I can go
$user_input = $the_password
and if it's a match then that's good.
It's when it comes to the username that I'm having problems, as I want it to be case insensitive.
Any pointers?
I want to compare two items, they will be text strings and one will, eventually, be the input from a form.
It's basically a username and password submittal form. I want the user name to be case insensitive, but the password, obviously to be case sensitive.
I *think* the password bit is easy, because I can go
$user_input = $the_password
and if it's a match then that's good.
It's when it comes to the username that I'm having problems, as I want it to be case insensitive.
Any pointers?
#10
Scooby Regular
Join Date: Apr 1999
Location: Bore Knee Muff
Posts: 3,666
Likes: 0
Received 0 Likes
on
0 Posts
john's right, convert them both toupper() or tolower()
uk.php.net is your friend!
PHP: strtoupper - Manual
PHP: strtolower - Manual
Also, dont forget if $user_input = "abc" and $the_password="def" after you do if($user_input = $the_password) echo 'blah';
then $user_input will be "def"
You must use == with IF statements unlike asp
uk.php.net is your friend!
PHP: strtoupper - Manual
PHP: strtolower - Manual
Also, dont forget if $user_input = "abc" and $the_password="def" after you do if($user_input = $the_password) echo 'blah';
then $user_input will be "def"
You must use == with IF statements unlike asp
#12
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
It worked brilliantly. Thank you both
I've now got a form that checks username and password, makes sure mandatory fields are filled out and also checks people are not putting URL's where they should not be, and it also removes funny characters from fields.
I've now got a form that checks username and password, makes sure mandatory fields are filled out and also checks people are not putting URL's where they should not be, and it also removes funny characters from fields.
Thread
Thread Starter
Forum
Replies
Last Post
shorty87
Full Cars Breaking For Spares
19
22 December 2015 11:59 AM