synchro_irl Posted February 28, 2008 Share Posted February 28, 2008 hey guys hope everyone is keeping well i have a login in my website, and i want the login code to bring the user to a html page, however i used the php code: include 'adminSearch1.html'; and it opened adminSearch1.html' within the current page. how do i open adminSearch1.html independantly? thanks for the help Steve Quote Link to comment Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 <?php header("Location: 'adminSearch1.html'); exit(); ?> Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 28, 2008 Author Share Posted February 28, 2008 <?php header("Location: 'adminSearch1.html'); exit(); ?> thanks for that, but it ust does nothing, when i log in then, and i know that 'adminSearch1.html' is ok, and uploaded onto the server any ideas? Quote Link to comment Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 Post your code! Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 28, 2008 Author Share Posted February 28, 2008 here it is, thanks guys! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Pluralism Description: A two-column, fixed-width template fit for 1024x768 screen resolutions. Version : 1.0 Released : 20071218 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Search4Trade</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper" style="width: 961px; height: 564px"> <div id="wrapper2"> <div id="header"> <div id="logo"> <h1><font size="6"> <a href="index.html">search4trade.net</a></font></h1> </div> <div id="menu"> <ul> <li></li> <li> <a href="Search1.html">Search </a></li> <li> <a href="Login1.php">Login</a></li> <li> <a href="phpBB2/index.php">Forum</a></li> <li> <a href="registration.html">Register</a></li> <li> <a href="comments.html">Star Rating</a></li> <li> <a href="contact.php">Contact</a></li> </ul> </div> </div> <div id="page"> <div id="content" style="width: 861px; height: 227px"> <div class="post"> <blockquote> <blockquote> <blockquote> <h2 class="title"><a href="#">Welcome to Search4Trade</a></h2> <blockquote> <div class="entry"> <?php mysql_connect("") or die(mysql_error()); mysql_select_db("mydatabase") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['username']; $pass = $_COOKIE['password']; $check = mysql_query("SELECT * FROM myadmin WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: submit.html"); } } } //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 $check = mysql_query("SELECT * FROM myadmin 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 adminstrator does not exist in our database.'); } 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); header("Location: 'adminSearch1.html'"); exit(); }}} else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST"> <blockquote> <table border="2" width="425" height="169" bgcolor="#FFFFFF"> <tr> <td colspan=2 bordercolorlight="#FFFFFF"> <h1 align="center">Admin Login</h1> </td> </tr> <tr> <td> <p align="center">Username:</td> <td> <p align="center"> <input type="text" name="username" maxlength="40" size="41"> </td> </tr> <tr> <td> <p align="center">Password:</td> <td> <p align="center"> <input type="password" name="pass" maxlength="50" size="41"> </td> </tr> <tr> <td colspan="2" align="right"> <p align="center" style="text-align: center"> <input type="submit" name="submit" value="Login" style="float: right"></td> </tr> </table> <p align="center"> </p> <p align="center"> <a href="http://www.dewalt.com"> <img border="0" src="images/dewalt-L.jpg" width="427" height="67"></a></p> </blockquote> </form> <?php } ?> </div> </blockquote> </blockquote> </blockquote> </blockquote> </div> </div> </div> </div> </div> <blockquote> <p align="center"> <span style="font-family: Angsana New;"> Copyright © Search4Trade.net 2008</span> </p> </blockquote> </body> </html> Quote Link to comment Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 You cannot call the header function after any output has been sent to the browser. You will need to arrange your code so that your login script appears prior to any html. Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 What he said! Move this code to the top of your script: <?php mysql_connect("") or die(mysql_error()); mysql_select_db("mydatabase") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['username']; $pass = $_COOKIE['password']; $check = mysql_query("SELECT * FROM myadmin WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: submit.html"); } } } Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 28, 2008 Author Share Posted February 28, 2008 but that code is at the top of the php script, can it go any higher? thanks again lads What he said! Move this code to the top of your script: <?php mysql_connect("") or die(mysql_error()); mysql_select_db("mydatabase") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['username']; $pass = $_COOKIE['password']; $check = mysql_query("SELECT * FROM myadmin WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: submit.html"); } } } Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 The script includes the HTML that comes before the php. Move that bit of PHP to the top of your document before even the HTML Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 28, 2008 Author Share Posted February 28, 2008 The script includes the HTML that comes before the php. Move that bit of PHP to the top of your document before even the HTML ok, can someone show me how to do this please im not really sure wat do to thanks guys Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 Highlight the code I showed you. Right click. Choose 'cut'. Go to the very top of the document, before the spot where it says <!doctype, and enter your cursor there. Right click and choose 'paste'. Then add: ?> at the end of the text you just pasted, and add: <?php in the spot where you cut the text from. Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 28, 2008 Author Share Posted February 28, 2008 thanks for the heko there, well appreciated unforutnately its not working, when i log in now it just shows me the css template,rather than vringing me to adminSearch1.html, is the code right nw, just in case: <?php mysql_connect("sql6.hosting365.ie", "Search4_admin1", "clio172") or die(mysql_error()); mysql_select_db("Search4_mydatabase") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['username']; $pass = $_COOKIE['password']; $check = mysql_query("SELECT * FROM myadmin WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: submit.html"); } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Pluralism Description: A two-column, fixed-width template fit for 1024x768 screen resolutions. Version : 1.0 Released : 20071218 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Search4Trade</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper" style="width: 961px; height: 564px"> <div id="wrapper2"> <div id="header"> <div id="logo"> <h1><font size="6"> <a href="index.html">search4trade.net</a></font></h1> </div> <div id="menu"> <ul> <li></li> <li> <a href="Search1.html">Search </a></li> <li> <a href="Login1.php">Login</a></li> <li> <a href="phpBB2/index.php">Forum</a></li> <li> <a href="registration.html">Register</a></li> <li> <a href="comments.html">Star Rating</a></li> <li> <a href="contact.php">Contact</a></li> </ul> </div> </div> <div id="page"> <div id="content" style="width: 861px; height: 227px"> <div class="post"> <blockquote> <blockquote> <blockquote> <h2 class="title"><a href="#">Welcome to Search4Trade</a></h2> <blockquote> <div class="entry"> <?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 $check = mysql_query("SELECT * FROM myadmin 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 adminstrator does not exist in our database.'); } 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); header("Location: 'adminSearch1.html'"); exit(); }}} else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST"> <blockquote> <table border="2" width="425" height="169" bgcolor="#FFFFFF"> <tr> <td colspan=2 bordercolorlight="#FFFFFF"> <h1 align="center">Admin Login</h1> </td> </tr> <tr> <td> <p align="center">Username:</td> <td> <p align="center"> <input type="text" name="username" maxlength="40" size="41"> </td> </tr> <tr> <td> <p align="center">Password:</td> <td> <p align="center"> <input type="password" name="pass" maxlength="50" size="41"> </td> </tr> <tr> <td colspan="2" align="right"> <p align="center" style="text-align: center"> <input type="submit" name="submit" value="Login" style="float: right"></td> </tr> </table> <p align="center"> </p> <p align="center"> <a href="http://www.dewalt.com"> <img border="0" src="images/dewalt-L.jpg" width="427" height="67"></a></p> </blockquote> </form> <?php } ?> </div> </blockquote> </blockquote> </blockquote> </blockquote> </div> </div> </div> </div> </div> <blockquote> <p align="center"> <span style="font-family: Angsana New;"> Copyright © Search4Trade.net 2008</span> </p> </blockquote> </body> </html> Highlight the code I showed you. Right click. Choose 'cut'. Go to the very top of the document, before the spot where it says <!doctype, and enter your cursor there. Right click and choose 'paste'. Then add: ?> at the end of the text you just pasted, and add: <?php in the spot where you cut the text from. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted February 28, 2008 Share Posted February 28, 2008 Do this... <?php ob_start(); mysql_connect("sql6.hosting365.ie", "Search4_admin1", "clio172") or die(mysql_error()); mysql_select_db("Search4_mydatabase") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['username']; $pass = $_COOKIE['password']; $check = mysql_query("SELECT * FROM myadmin WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { ob_clean(); $location = "location: /submit.html"; header('HTTP/1.0 302 Found'); header($location); exit(); } } } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 Don't do that - ob_start() only masks problems, it doesn't solve them. unforutnately its not working, when i log in now it just shows me the css template,rather than vringing me to adminSearch1.html, What do you mean its only showing the CSS template? And you haven't put adminSearch1.html anywhere in the code, so thats probably why its not forwarding you there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.