Kun en include "dbconnect.php";
Hvordan kan jeg gøre i det her script så jeg kun har 1 include("dbconnect.php"); isetedet for 2.én for hver gang jeg skal åbne forbindelse til database, kan man ike globalisere den.
og er der noget sikkerhed jeg skal tænke på?
Mvh krydset
----------------------------------------------------------
<?PHP
session_start();
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s ") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
/*
* +-----------------------------------------------------------------------------+
* Projekt Name: Php script database
* +-----------------------------------------------------------------------------+
* Copyright Notes: Copyrights 2003 pc-dk.dk
* +-----------------------------------------------------------------------------+
* Disclaimer Notice(s)
* DONT USE THIS SCRIPT UNLESS YOU HAVE MY PERMISSIONS ON PARER
* WITH MY PERSONAL SIGNATURE ANY QUESTIONS FOR THAT
* SEND ME A MAIL: TLARSEN@PC-DK.DK
* IF YOU WANT TO USE THIS SCRIPT THEN MAIL ME AND PAY FOR IT
* +-----------------------------------------------------------------------------+
* Author(s): Thomas Larsen / Dk-Medieburner E-Mail: Tlarsen@pc-dk.dk
* +-----------------------------------------------------------------------------+
*/
error_reporting(E_ALL); //For debuggin only, prints all error!
//remove the # to debug
/**
* Module comments (Brief shorly what this piece of code do)
This script is registering a user
*/
/*
Here starts the code
*/
//to awoid a warning i am setting $need and $ikke_ens and $bruger_findes to emty here
$need = "";
$ikke_ens = "";
$bruger_findes = "";
//if the user press the submit button named "opret" then ---->
if (isset($_POST['login']))
{
//checks that all required fields are filled and the user accept
//The rule set.
if ($_POST['name'] == "" or $_POST['last_name'] == "" or $_POST['e_mail'] == "" or $_POST['user_name'] == "" or $_POST['pass_word'] == "" or $_POST['re_pass_word'] == "" or $_POST['regel'] == "")
{
$need = "***DU mangler at udfylde noget****";
}
else
{ //if not the password and re password are equal
if($_POST['pass_word'] !== $_POST['re_pass_word'])
{
$ikke_ens = "Passwords er ikke ens";
}
else
{
//Includes the file there is conn. to the databse
include("../ext/dbconnect.php");
//Here it checks that the user not exist in the databse
$tjek = mysql_query("SELECT user_name FROM users WHERE user_name = '$_POST[user_name]'") or die(mysql_error());
$antal = mysql_num_rows($tjek);
if (!$antal == 0)
{
$bruger_findes = "Brugern findes tryk tilbage og prøv et nyt brugernavn";
}
else
{
//Includes the file there is conn. to the databse
include("../ext/dbconnect.php");
//This query inserts data from the form into the database
$res = mysql_query("INSERT INTO users (name, last_name, icq, messenger, e_mail, user_name, pass_word) VALUES ('$_POST[name]','$_POST[last_name]','$_POST[icq]','$_POST[messenger]','$_POST[e_mail]','$_POST[user_name]','$_POST[pass_word]')") or die(mysql_error());
header("location: http://www.jubii.dk");
}
}
}
}
/*
Here stops the code
if you have any html
write it belowe here
*/
?>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../ext/style.css">
</head>
<body bgcolor="#066982">
<form action="opret.php" method="POST">
<table align="center">
<tr>
<td>* Navn:</td>
<td><input type="text" name="name" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>* Efternavn</td>
<td><input type="text" name="last_name" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>Icq:</td>
<td><input type="text" name="icq" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>Messenger:</td>
<td><input type="text" name="messenger" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>* E-Mail</td>
<td><input type="text" name="e_mail" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>* Brugernavn:</td>
<td><input type="text" name="user_name" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>* Adgangskode:</td>
<td><input type="password" name="pass_word" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td>* Gentag adgangskode:</td>
<td><input type="password" name="re_pass_word" style="width:100px; height:20px;" id="txt_box"></td>
</tr>
<tr>
<td><input type="submit" name="login" value="Opret bruger" style="width:80px; background:transperant;" id="submit"></td>
</tr>
<tr>
<td>Har læst og accepteret regelsættet <a href="regel.php" title="Læs reglerne her">Tryk her</a></td>
<td><input type="checkbox" name="regel" value="ja"></td>
</tr>
<tr>
<td>Dem med * skal udfyldes</td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<td><?php echo $need; ?></td>
</tr>
<tr>
<td><?php echo $ikke_ens; ?></td>
</tr>
<tr>
<td><?php echo $bruger_findes; ?></td>
</tr>
</table>
</form>
</body>
</html>
