Jump to content

Login help :)


mancombe

Recommended Posts

hello im new to php and i tried to write a login script but when i run it i get code on my page so i must have made a mistake either missed something a tag or such  mayb a morecitical error either way its anoying and i cant find it  :(

<?php

mysql_connect("myhost here", "myuser", "mypass") or die(mysql_error());
mysql_select_db("db0819443") or die(mysql_error());


if(isset($_COOKIE['ID_my_site']))

{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM members WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
	if ($pass != $info['password'])
	{
}
else
{
	header("Location: members.php");

	}
}
}


if (isset($_POST['submit'])) { 


if(!$_POST['username'] | !$_POST['pass']) {
	die('You did not fill in a required field.');
}

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


$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database.');
<a href=register.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");
	}
}
}
?>

<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>
<p>

 

any help would be cool :)

Link to comment
Share on other sites

can't really see anything that would make your code show up in the browser, did you save the page with .php extension ?

yeah its saved as index.php it was login.php but i had to rename it index because it would not show whn i uploaded it. What i see is the uernam and password box but above that it shows a lot of the php code i think the error is some place by the link they click if the are not a member click here to register. Quite anoying really :/ but thanks for taking a look
Link to comment
Share on other sites

How are you attempting to run the file? Does it have a file extenion of PHP? Are you running it locally? If so do you have a server setup which supports PHP (such ie WAMP, XAMPP, LAMP etc.)? Are you placing the file in the RootDirectory of your server and accessing it in your browser using http://localhost/folder_name?

yeah im uploading it to the rootDirectory on my univercity account and to view the pages i have to type the exact url such as www.my-linux/studentnumber
Link to comment
Share on other sites

It will display the code if the server doesn't know to parse it, does your university account actually support PHP?

i should hope so its a php module :) yeah it does lol thats the server they set up for me to upload it if you rename the register.php index.php it lets them register but its just the login page shows "some" of the code :/
Link to comment
Share on other sites

You say 'some' of the code, which bits? If you used short code tags, theres a fair chance the server doesn't support it. So if you used...

 

<? echo "something"; ?> // the output may be '<? echo "something"; ?>'

// whereas this

<?php echo "something"; ?> // the output would be 'something';

Link to comment
Share on other sites

You say 'some' of the code, which bits? If you used short code tags, theres a fair chance the server doesn't support it. So if you used...

 

<? echo "something"; ?> // the output may be '<? echo "something"; ?>'

// whereas this

<?php echo "something"; ?> // the output would be 'something';

the part of code that shows on the pages start at where i have Click Here to Register and it goes all the way down to  header("Location: members.php");

 

:shy:

Link to comment
Share on other sites

If you'd have mentioned that to start with....

 

You have...

 

<a href=register.php>Click Here to Register</a>

 

... written in the middle of a block of php which is invalid. Any HTML directly inside a php block (ie <?php ?>) should either be part of an echo/print statement. You cannot just write html code inside PHP. Also the location you've put it in doesn't seem valid since as soon as you call die() on the line before hand the script will stop running.

Link to comment
Share on other sites

If you'd have mentioned that to start with....

 

You have...

 

<a href=register.php>Click Here to Register</a>

 

... written in the middle of a block of php which is invalid. Any HTML directly inside a php block (ie <?php ?>) should either be part of an echo/print statement. You cannot just write html code inside PHP. Also the location you've put it in doesn't seem valid since as soon as you call die() on the line before hand the script will stop running.

Thanks you very much you was quite correct moved this tag outside the php script and i no longer have the script showing on my screen  :D
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.