Page 1 of 1

HELP ME : How to paste PHP login script onto image?

Posted: Fri Jun 27, 2008 6:28 am
by azhan
Hye guys!

Im a newbie on PHP scripting, my problem is I couldnt paste PHP login script onto any image that i like. I try using Adobe Dreamweaver to adjust the login script to be in the middle of my image but i still couldnt make it, please refer image below

Image

the BLACK shaded area indicates my chosen image and the RED area is where i wanted to put my php login script. The problem is i couldnt freely adjust it exactly to the middle of the image. Is there any special script to do this?

please please help me, i wanted to make a intro login page of my database website.

thanks
Azhan
________________________________________
http://www.productcoverdesign.com - Cheapest E-Cover u'll ever get!

Re: HELP ME : How to paste PHP login script onto image?

Posted: Fri Jun 27, 2008 6:49 am
by jayshields
This should be moved to client-side. You need to look into HTML and CSS, especially the text-align and line-height attributes.

Re: HELP ME : How to paste PHP login script onto image?

Posted: Fri Jun 27, 2008 8:33 am
by madan koshti
the simple sol is :


<table border="0" background="logo_i.gif" height=100px width="100px">
<tr >
<td align="center" valign="center">
<?php echo "php code here"; ?>
</td>
</tr>
</table>

just u can adjust heightt and width ..

got some error...

Posted: Fri Jun 27, 2008 1:18 pm
by azhan
the simple sol is :


<table border="0" background="logo_i.gif" height=100px width="100px">
<tr >
<td align="center" valign="center">
<?php echo "php code here"; ?>
</td>
</tr>
</table>

just u can adjust heightt and width ..
hey madan...I still got error..the placing is perfect already....the problem is with the php code to be insert in the code that u just propose.....do i have to include the initial code of php that is <?php and end by ?> .....??

by the way..this is my whole php login script.....PLEASE tell me which part of my script should be IN or OUT...thanks again madan and others....please help me...huhu

login script :
_________________________________________________________________
<?php
// Connects to your Database
mysql_connect("hostname", "username", "password") or die(mysql_error());
mysql_select_db("login") or die(mysql_error());

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))

//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: members.php");

}
}
}

//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted

// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);

//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}

else
{

// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);

//then redirect them to the members area
header("Location: members.php");
}
}
}
else
{

// if they are not logged in
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}

?>
________________________________________________________________________
Problem: After i paste all my php script into the "php code here" just like madan said, it seems there is errors occurred.Below are the image of the errors.....i've circle the error part in YELLOW COLOUR.

Image

regards,

Azhan
________________________
http://www.productcoverdesign.com

Re: HELP ME : How to paste PHP login script onto image?

Posted: Fri Jun 27, 2008 1:24 pm
by dyluck
Ok I see the problem:

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<table border="0"> 
<tr><td colspan=2><h1>Login</h1></td></tr> 
<tr><td>Username:</td><td> 
<input type="text" name="username" maxlength="40"> 
</td></tr> 
<tr><td>Password:</td><td> 
<input type="password" name="pass" maxlength="50"> 
</td></tr> 
<tr><td colspan="2" align="right"> 
<input type="submit" name="submit" value="Login"> 
</td></tr> 
</table> 
</form> 
<?php 
} 
 
?>
You were missing a ; after $_SERVER['PHP_SELF']
How does that fair?

Re: HELP ME : How to paste PHP login script onto image?

Posted: Fri Jun 27, 2008 7:30 pm
by califdon
Moved to Client Side.

still not solve

Posted: Sat Jun 28, 2008 2:58 am
by azhan
hey guys....im still stuck...for mr dyluck..is still doesnt work...u said i have to put ";" right?...but after i done that...the php script become all in brown colour..which mean doesnt valid...huhu

please please help me..it seems to be simple but its not...

can u guys try it out and tell me does it work for u guys in dreamweaver? i've already paste the whole php script on the previous thread...and apply it on this :
-----------------------------------------------------------------------
<table border="0" background="logo_i.gif" height=100px width="100px">
<tr >
<td align="center" valign="center">
<?php echo "php code here"; ?>
</td>
</tr>
</table>
---------------------------------------------------------------- taken from madan koshti

thanks
Azhan
_____________________
http://www.productcoverdesign.com

Re: HELP ME : How to paste PHP login script onto image?

Posted: Sat Jun 28, 2008 3:27 am
by madan koshti
just paste all code here with login script + background image code .........

It seems that the php code start end missing / missmatch..

Re: HELP ME : How to paste PHP login script onto image?

Posted: Sat Jun 28, 2008 11:20 am
by dyluck
Yeah please post the code and we will do what we can to test it out for you.
I did test the code above, commented out your database stuff and I don't get any issues with text display. It even returns the errors when i try to "login"

Also, why are you not using DIV? / CSS for this? would be a little better for this application then tables, but that is just me.

Secondly... I noticed your script tests for a cookie then headers them to members area... This is a decent security hole... Cookies can be intercepted. :) just thought I would point that out.

Re: HELP ME : How to paste PHP login script onto image?

Posted: Sat Jun 28, 2008 12:53 pm
by azhan
im not familiar with DIV or CSS.....hehe..dat is why im just searching for script and try it out...yerp,this login are directed to membership area
dyluck wrote:Secondly... I noticed your script tests for a cookie then headers them to members area... This is a decent security hole... Cookies can be intercepted. :) just thought I would point that out.
u mean that my page could be hack? damn....heheh....actually im trying to build a "Database Driven Website" which using my own PC as a server using mysql. U guys dont need to test the login function cos the localhost is my pc, so it will bring error if u try the login function. All i need is the php function to be in the middle of the image. Below are the whole php codes for login area.

Code: Select all

<?php 
// Connects to your Database 
mysql_connect("hostname", "username", "password") or die(mysql_error()); 
mysql_select_db("login") or die(mysql_error()); 
 
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
 
//if there is, it logs you in and directes you to the members page
{ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) 
{
if ($pass != $info['password']) 
{
}
else
{
header("Location: members.php");
 
}
}
}
 
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
 
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
 
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
 
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check )) 
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
 
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
 
else 
{ 
 
// if login is ok then we add a cookie 
$_POST['username'] = stripslashes($_POST['username']); 
$hour = time() + 3600; 
setcookie(ID_my_site, $_POST['username'], $hour); 
setcookie(Key_my_site, $_POST['pass'], $hour); 
 
//then redirect them to the members area 
header("Location: members.php"); 
} 
} 
} 
else 
{ 
 
// if they are not logged in 
?> 
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
<table border="0"> 
<tr><td colspan=2><h1>Login</h1></td></tr> 
<tr><td>Username:</td><td> 
<input type="text" name="username" maxlength="40"> 
</td></tr> 
<tr><td>Password:</td><td> 
<input type="password" name="pass" maxlength="50"> 
</td></tr> 
<tr><td colspan="2" align="right"> 
<input type="submit" name="submit" value="Login"> 
</td></tr> 
</table> 
</form> 
<?php 
} 
 
?>
 
and this is the url of the image, u guys can save it and try it out.
http://i237.photobucket.com/albums/ff24 ... inpage.jpg

Im really really appreciate that u guys intended to help me....
BY the way, i get the php login script from here
->> http://php.about.com/od/finishedphp1/ss ... code_4.htm

PS: If u guys could solve it, could u guys paste the whole correct code back to me?
many thanks,
Azhan
______________________
http://www.productcoverdesign.com - "Cheapest E-cover Design"

Re: HELP ME : How to paste PHP login script onto image?

Posted: Sat Jun 28, 2008 8:08 pm
by dyluck
Alright bro here yah go.. you will need to play with the style of your form, but its what you are looking for. Just make sure that the Image is in the correct folder location.
(line with: background-image: url(loginpage.jpg);
the loginpage.jpg is pointing to the location you have the image actually saved.

Also, when you do get time, try learning CSS and using DIVs instead of tables, but I used tables here for you as this is what you are working with.

Cheers :)

Code: Select all

<?php 
// Connects to your Database 
mysql_connect("hostname", "username", "password") or die(mysql_error()); 
mysql_select_db("login") or die(mysql_error()); 
 
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
 
//if there is, it logs you in and directes you to the members page
{ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) 
{
if ($pass != $info['password']) 
{
}
else
{
header("Location: members.php");
 
}
}
}
 
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
 
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
 
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
 
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check )) 
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
 
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
 
else 
{ 
 
// if login is ok then we add a cookie 
$_POST['username'] = stripslashes($_POST['username']); 
$hour = time() + 3600; 
setcookie(ID_my_site, $_POST['username'], $hour); 
setcookie(Key_my_site, $_POST['pass'], $hour); 
 
//then redirect them to the members area 
header("Location: members.php"); 
} 
} 
} 
else 
{ 
 
// if they are not logged in 
?><style type="text/css">
<!--
body {
    background-image: url(loginpage.jpg);
    background-position: center center;
    background-repeat: no-repeat;
}
-->
</style> 
 
<table border="0" width="100%" height="100%">
<tr><td>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<center><table border="0"> 
<tr><td colspan=2><h1>Login</h1></td></tr> 
<tr><td>Username:</td><td> 
<input type="text" name="username" maxlength="40"> 
</td></tr> 
<tr><td>Password:</td><td> 
<input type="password" name="pass" maxlength="50"> 
</td></tr> 
<tr><td colspan="2" align="right"> 
<input type="submit" name="submit" value="Login"> 
</td></tr> 
</table></center>
</form> 
</td>
</tr>
</table>
 
<?php 
} 
 
?>

THANKS!

Posted: Sat Jun 28, 2008 11:04 pm
by azhan
Thanks to dyluck and others for helping me....I FINALLY obtain the solution!!! hahhahahha...im damn happy now :D ...the next step is to learn CSS and DIV just like dyluck said.....i've found this one website that selling all kind of web developing books...it called http://www.sitepoint.com cos i couldnt expect anything to be free right? or u guys had any suggestion on where could i learn for free?

THANKS TO DYLUCK and MADAN KOSHTI !!
U guys are really really nice guy...

thanks again,

____________________
Azhan
http://www.productcoverdesign.com - "Cheapest E-cover Design"