Jump to content

Php login, register,cookie cheack, and fwrite help plz


mikemanx2

Recommended Posts

Hi, ok well i have 4 php scripts that i need help fixing ok the first one is my register.php with this one i need help puting in the part ware it says if a user alredy has that username it will say username alerdy taken but i dont know that part of the script.Register.php

<?php// Define variables and connect to database$Account_Username = $_POST['Account_Username'];$Account_Password = $_POST['Account_Password'];$Account_PasswordConfirm = $_POST['Account_PasswordConfirm'];$Contact_FullName = $_POST['Contact_FullName'];$Contact_ZipCode = $_POST['Contact_ZipCode'];$Contact_Country = $_POST['Contact_Country'];$Contact_Email = $_POST['Contact_Email'];$Contact_URL = $_POST['Contact_URL'];// Connect to database$dbuser = "*****";$dbpass = "*****";$host = "*****";$db_connect = mysql_connect($host, $dbuser, $dbpass) or die("Could not connect to database");$select_db = mysql_select_db("******", $db_connect) or die("Could not select database");// Check values of First password and Second password to see if they are the same.if($Account_Password != $Account_PasswordConfirm) {echo "Your passwords do not match. <a href='java script: history.go(-1)'>Click Here</a> to go back.";die;}// Check values of First password and second password to see if they are nullif($Account_Password == '' || $Account_PasswordConfirm == '' || $Account_Username == '' || $Contact_FullName == '' || $Contact_Email == '') {echo "You must enter all *Required spaces. <a href='java script: history.go(-1)'>Click Here</a> to go back.";die;}// Encrypt the password with a hash.$encrypted_pass = md5($Account_Password);// Write and execute the query.$query = "INSERT into members (member_id,username,memberpass) VALUES ('','$Account_Username','$encrypted_pass')";$result = mysql_query($query) or die ("Could not execute query." . mysql_error());// Check if the result was successful.if($result) {echo "You registered successfully!<p><a href='memberlogin.php?PHPSESSID=b1491388a4ad30f954d8d92267706d9d'>Click Here</a> to login.";die;}?>

The next one is my login.php ok when you try to login its a blank page like theres nothing on it thats thats the thing i need help to fix on that page.login.php

<?php// Define variables and connect to database$Account_Username = $_POST['Account_Username'];$Account_Username = $_POST['Account_Username'];// Connect to database$dbuser = "****";$dbpass = "****";$host = "****";$db_connect = mysql_connect($host, $dbuser, $dbpass) or die("Could not connect to database");$select_db = mysql_select_db("******", $db_connect) or die("Could not select database");// Now to encrypt the password.$encrypted_pass = md5($pass);// Define the query:$query = "SELECT username, memberpass FROM members WHERE username='" . mysql_escape_string($Account_Username) .' AND memberpass='{$encrypted_pass}'";// Run the query and check if it worked.$result = mysql_query($query) or die("Could not execute query." . mysql_error());if (mysql_num_rows($result) > "0"){ session_start(); $_SESSION['Account_Username'] = $Account_Username; $_SESSION['pass'] = $encrypted_pass; if ($the_user_wants_to_be_logged_in_for_a_year) {   setcookie("siteuser", $user, time() + (86400 * 365), "/", $_SERVER["HTTP_HOST"], 0);   setcookie("sitepass", $encrypted_pass, time() + (86400 * 365), "/", $_SERVER["HTTP_HOST"], 0); }  write_session();}else{ // bad login, send them back to the login page with an error header("Location: login.php?error=" . urlencode("Username or password incorect"); exit();}?>

the next thing is my index.php ok on this page i want it to be ware the login part of the page if your logged in and theres a cookie it will say your logged in as "username"but it is also a blank page when you go to it index.php

<html><head><STYLE TYPE="text/css"><!--FORM { margin-bottom : 0px; margin-top : 0px; }bodya { text-decoration: none; }a:link { color: #FF0000; }a:visited { color: #FF0000; }a:active { color: #FF0000; }a:hover { color: #FF0000; }body, div, td{	scrollbar-face-color: #000000;	scrollbar-highlight-color: #FF0000;	scrollbar-3dlight-color: #000000;	scrollbar-darkshadow-color: #000000;	scrollbar-shadow-color: #000000;	scrollbar-arrow-color: #FF0000;	scrollbar-track-color: #FF0000;}.font_contact{	font-family: Arial,Helvetica;	font-size: 10px;}.font_vd_small{	font-family: Verdana,Arial,Helvetica;	font-size: 10px;}.font_a2{	font-family: Arial,Helvetica;	font-size: 13px;}a.header:link { color: #00FF00; }a.header:visited { color: #00FF00; }a.header:hover { color: #00FF00; }a.header:active { color: #00FF00; }.font_header{	font-family: Arial,Helvetica;	font-size: 10px;	font-weight: bold;	letter-spacing: 1px;}.font_small_header{	font-family: Arial,Helvetica;	font-size: 9px;}//--></STYLE><title>Mikemanx A Programers Dream</title></head><body bgcolor="#000000" text="#00FF00"><div align="center">  <center>  <table border="1" width="948" height="4">	<tr>	  <td width="674" height="4">		<form action="--WEBBOT-SELF--" method="POST">		<p> Mikemanx.com Home                                                                                                        		Language: English</td>	  <td width="258" height="4">  Search For <b> </b> <input type="text" size="14" maxlength="256" name="searcht">		<input type="submit" value="Search"></td>	</tr>  </table>  </center></div><div align="center">  <center>  <table border="0" width="948" height="150">	<tr>	  <td width="698" height="146"><img border="0" src="logo.png" width="700" height="153"></td>	  <td width="230" height="146">		<h5 class="heading">                       <?php if(ISSET("siteuser")) {?> You are Loggedin as <a href="userpage.php"><?php echo $_POST["siteuser"]; ?></a><?php }else {echo "<font color="#FF0000">Member Login</font></h5>			<form action="memberlogin.php" method="post">				<div class="row">					<label for="user">Username:</label>					<input type="text" name="user"><br/>				</div>				<div class="row">								<label for="password">Password:</label> <input type="password" name="pass"><br/>								</div>				<div align="center">					<input type="submit" value="Login" alt="Log In">					 				</div>				<div align="center">					<font color="#FF0000">					<a id="ctl00_Main_SplashDisplay1_login1_HyperLink1" href="register.html">Register A New User</a><br>					<a href="http://www.mikemanx.com/passforget.html">Forgot your password?</a>					</font>				</div>			</form>";die;}?>		</td>	</tr>  </table>  </center></div><div align="center">  <center>  <table border="1" width="948" height="265">	<tr>	  <td width="151" height="253"><img border="0" src="Navbar.png" width="151" height="46">		<font size="3"><a href="index.html">Home</a><br>		<a href="programpics.php">		Programming Photos</a> <a href="register.html">Register</a><br>		<a href="download.html">		Downloads</a><br>		<a href="submittut.php">		Submit Tutorial</a><br>		<a href="userlookup.php">		All Users</a><br>		<a href="walloffame.php">		Wall Of Fame</a><br>		<a href="programmissions.php">		Programming Missions</a><br>		<a href="http://www.mikemanx.com/fourm">		Forums</a><br>		<a href="subbug.php">		Submit Bug </a><br>		<a href="help.php">		Help</a></font>		<p><img border="0" src="Navtutbar.png" width="150" height="35"></p>		<p><font size="3"><u><a href="c++.php">Tutorial</a></u> <a href="c++.php"> C++</a><br>		<u><a href="html.php">Tutorial</a></u>  <a href="html.php"> Html</a><br>		<u><a href="php.php">Tutorial</a></u> <a href="php.php"> Php</a><br>   		<u><a href="sql.php">Tutorial</a></u> <a href="sql.php"> Sql</a><br>		<u><a href="java.php">Tutorial</a></u> <a href="java.php"> Java</a><br>		<u><a href="javascript.php">Tutorial</a></u> <a href="javascript.php"> Javascript</a><br>		 </font><br>		<a href ="Http://www.hackthissite.org"><img border="0" src="hacksitelogo.gif" width="151" height="34"></a>		</p>	  </td>	  <td width="778" height="265">		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </p>		<p> </td>	</tr>  </table>  </center></div></body></html>

and the last thing i need help with is my c++w.php ok im trying to make a thing ware you can submit a tutorail but when you click submit the the submition page it goos to this page and its blank we need to fix that and i want it ware it dusent stop on that page it redirecs to the page it is supost to write the tutoail on.C++w.php

<?php$name = $_POST['name'];$text = $_POST['text'];$file = "c++.php";$f = fopen($file, 'a');$write = fwrite($f, $name "<p>" . $text . "<hr>");header("location: c++.php");?>

I hope you guys will plz help me with my problomes thxs :)

Link to comment
Share on other sites

If you want to check if the user name is taken, do a select query for the user name, and use mysql_num_rows to see if any rows were returned. If rows were returned, the user exists.

The next one is my login.php ok when you try to login its a blank page like theres nothing on it thats thats the thing i need help to fix on that page.
Well, you don't have the login page redirecting or sending any output, so of course it's blank. It sets the cookie then stops. Add a redirect header or output if you want it to do something.
the next thing is my index.php
Look at your code:
echo "<font color="#FF0000">Member Login</font></h5>			<form action="memberlogin.php" method="post">				<div class="row">					<label for="user">Username:</label>					<input type="text" name="user"><br/>				</div>				<div class="row">								<label for="password">Password:</label> <input type="password" name="pass"><br/>								</div>				<div align="center">					<input type="submit" value="Login" alt="Log In">					 				</div>				<div align="center">					<font color="#FF0000">					<a id="ctl00_Main_SplashDisplay1_login1_HyperLink1" href="register.html">Register A New User</a><br>					<a href="http://www.mikemanx.com/passforget.html">Forgot your password?</a>					</font>				</div>			</form>";die;

There are 2 main problems with this. The first problem is that you did not escape any quotes. Look at this line:echo "<font color="#FF0000">Member Login</font></h5>Look at where the quotes are, you are telling echo to print this:<font color=And then the rest of the line is a comment because of the # sign. If you want to use echo or print, you need to escape your quotes:echo "<font color=\"#FF0000\">Member Login</font></h5>Or else you can use a heredoc and write it normally:

echo <<<END_OF_FORM			<font color="#FF0000">Member Login</font></h5>			<form action="memberlogin.php" method="post">				<div class="row">					<label for="user">Username:</label>					<input type="text" name="user"><br/>				</div>				<div class="row">								<label for="password">Password:</label> <input type="password" name="pass"><br/>								</div>				<div align="center">					<input type="submit" value="Login" alt="Log In">					 				</div>				<div align="center">					<font color="#FF0000">					<a id="ctl00_Main_SplashDisplay1_login1_HyperLink1" href="register.html">Register A New User</a><br>					<a href="http://www.mikemanx.com/passforget.html">Forgot your password?</a>					</font>				</div>			</form>END_OF_FORM;

The second problem with this is the die statement. The die statement causes php.exe to end, so you are stopping the page when you have the die statement there. I'm pretty sure that's one of the reasons you aren't seeing anything.For the "c++.php" thing, you really don't want to have a plus sign in your filename. Plus means a space for certain URL encodings. If you insist on naming your file c++.php, you will probably need to refer to it in URLs as "c%43%43.php" to keep it legal. But it's probably just easier to call it something else, like cpp.php.

$write = fwrite($f, $name "<p>" . $text . "<hr>");

You're also missing a period between $name and "<p>".Also, what's with the legion of   characters? Haven't you heard of align?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...