lucky-8 wrote:I have 3 questions in mind....
Is this the correct style of coding or should i put in all kinds of querieng in one php class file and calling those methods only from a php file,
I'd put such functionality in at least function if not in a class, like for ex.:
<?php
function authenticate($user,$pass)
{
//do your sql here
if ($succes) return true;
else return false;
}
//when it's time to see if a user can be authenticated
if (authenticate($_POST['user'],$_POST['pass']))
{
//do something
}
else
{
//do something
}
lucky-8 wrote:
is it ok to have php in between the html like this.
Yes, it's just another way of echoing output to the browser. You can even close php tags inside if block (afair, not inside class definition).
lucky-8 wrote:
2.Once the user is authenticated from the database i want the browser to load another page how do i do that, i mean what code should i rite in the if.......... or should this be done rite on top before the headers are sent.
It can be done with headers. Using previous example:
if (authenticate($_POST['user'],$_POST['pass']))
{
header('Location: http://www.yoursite.com/authenticated/');
}
else
{
header('Location: http://www.yoursite.com/denied/');
}
Remember that headers can be send only if no output was started earlier. A couple of spaces or a newline befeore <?php count as an output.
lucky-8 wrote:
3. Using SQL injection i should be able to crack this password by entering
something' OR 'x=x but it doesnt crack......why is that?
Probably magic quotes. Php adds slashes before single quotes for you. It has to be turned on in php.ini but it is by default. Don't count on it though. Look at [man]mysql_real_escape_string[/man] and [man]get_magic_quotes_gpc[/man].