Forums
This topic is locked
form validation
Posted 19 Jan 2007 17:03:07
1
has voted
19 Jan 2007 17:03:07 Emma Webster posted:
Hi,Regarding form validation, does anyone know the code or what to do if you want only people with a certain username to be able to add to a database. So only people with the same email address extension can add entries into a database and if those email extensions dont match with a list, then the person gets a message saying invalid email. Onlypeople from company are be allowed into the website... thats why.
Replies
Replied 19 Jan 2007 18:24:15
19 Jan 2007 18:24:15 Alan C replied:
I think this is going to depend on how far down the development route you are, if you are near the start you can design your user tracking to accommodate this, if you have already gone some way then you may have to "bend" things a little.
I have a system that is based on a tutorial I found here evolt.org/node/60384
That was my starting point, it uses the usename plus password to log users in, then assigns them an access level from 1 to N. On each page you can add a bit of php that checks the user is logged in and what level of access they have then only show them appropriate parts of the page.
eg - at the top of the code,
include("include/session.php"
somewhere lower down . . .
<?php
if($session->logged_in){ // my logged-in check - see } before end of maincontent div for end of this block
?>
here is the html etc that logged-in users see
<?php
}
else
{
?>
the code that others see, what it actually says is something like, "You need to log in before managing your property, you will be redirected in 5 seconds"
Then there's a Javascript that does the redirection to the login page.
<?php
}
?>
If you only wanted to look at the email address you could extract the part that you are interested in and then check it, you could use a function like stripos() that finds substrings, there are a whole lot of similar functions (sorry if I'm telling you something you already know <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
You might not see all the php tags in this post, I think the forum code removes some of them.
I have a system that is based on a tutorial I found here evolt.org/node/60384
That was my starting point, it uses the usename plus password to log users in, then assigns them an access level from 1 to N. On each page you can add a bit of php that checks the user is logged in and what level of access they have then only show them appropriate parts of the page.
eg - at the top of the code,
include("include/session.php"
somewhere lower down . . .
<?php
if($session->logged_in){ // my logged-in check - see } before end of maincontent div for end of this block
?>
here is the html etc that logged-in users see
<?php
}
else
{
?>
the code that others see, what it actually says is something like, "You need to log in before managing your property, you will be redirected in 5 seconds"
Then there's a Javascript that does the redirection to the login page.
<?php
}
?>
If you only wanted to look at the email address you could extract the part that you are interested in and then check it, you could use a function like stripos() that finds substrings, there are a whole lot of similar functions (sorry if I'm telling you something you already know <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
You might not see all the php tags in this post, I think the forum code removes some of them.
Replied 21 Jan 2007 00:24:49
21 Jan 2007 00:24:49 Emma Webster replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
If you only wanted to look at the email address you could extract the part that you are interested in and then check it, you could use a function like stripos() that finds substrings, there are a whole lot of similar functions (sorry if I'm telling you something you already know <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
You might not see all the php tags in this post, I think the forum code removes some of them.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Hi,
Sorry, I dont know much about php! Im using JSP but this idea about using a stripos() function sounds like one that could work. Is this a function that would work in JSP and is the code something like: if stripos('email') = or then somthing = true else something=false.
Is this the way?
If you only wanted to look at the email address you could extract the part that you are interested in and then check it, you could use a function like stripos() that finds substrings, there are a whole lot of similar functions (sorry if I'm telling you something you already know <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
You might not see all the php tags in this post, I think the forum code removes some of them.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Hi,
Sorry, I dont know much about php! Im using JSP but this idea about using a stripos() function sounds like one that could work. Is this a function that would work in JSP and is the code something like: if stripos('email') = or then somthing = true else something=false.
Is this the way?
Replied 22 Jan 2007 21:00:39
22 Jan 2007 21:00:39 Alan C replied:
Hi
yes, sounds like it, I don't know any JSP.
php has a HUGE number of functions; good or bad depending on how you look at it <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
correct me if wrong . . . you have a domain something like my-site.co.uk so there are email addresses that look like
you want people who have an email address like that to be able to access your site but no-one else.
I guess you are using email address as user id or something like that. So somewhere you might assign the email address to a variable
$user_email = ' '; // your email address in a string
now you can test that using one of the string functions in php, you could say . . .
$findme = 'mysite,co.uk'; // what you want to look for
$pos = strpos($user_email, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$user_email'";
} else {
echo "The string '$findme' was found in the string '$user_email'";
echo " and exists at position $pos";
}
I have adapted this from
ca.php.net/manual/en/function.strpos.php
you need to use the === operator because it looks for an exact match, in php it's easy to mix up =, == and === and get unexpected results!
Hope that's what you were looking for. I'm sure there will be something in JSP that looks for one string contained within another
yes, sounds like it, I don't know any JSP.
php has a HUGE number of functions; good or bad depending on how you look at it <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
correct me if wrong . . . you have a domain something like my-site.co.uk so there are email addresses that look like
you want people who have an email address like that to be able to access your site but no-one else.
I guess you are using email address as user id or something like that. So somewhere you might assign the email address to a variable
$user_email = ' '; // your email address in a string
now you can test that using one of the string functions in php, you could say . . .
$findme = 'mysite,co.uk'; // what you want to look for
$pos = strpos($user_email, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$user_email'";
} else {
echo "The string '$findme' was found in the string '$user_email'";
echo " and exists at position $pos";
}
I have adapted this from
ca.php.net/manual/en/function.strpos.php
you need to use the === operator because it looks for an exact match, in php it's easy to mix up =, == and === and get unexpected results!
Hope that's what you were looking for. I'm sure there will be something in JSP that looks for one string contained within another