PHP
Grab the users IP address, handy to add to login scripts if you want to tighten security… Or to just keep track…
$Users_IP_address = $_SERVER["REMOTE_ADDR"];
If the user is operating via a proxy server, the above code may not work. In this case use this simple function:
<?php
function…
In a nutshell, it makes a string safe to be entered into a database….
For example:
$email = '[email protected]'; // This could come from a form, etc.
$result = mysql_query("SELECT * FROM `userTable` WHERE `userEmail`= '".mysql_real_escape_string($email)."'");
This example checks to see if an…
This is the most recent version of the script I’m using… Copy and Paste the code straight into a page and save it as yourfilename.php, and that’s about it…. You just need to change the name and e-mail address from mine to yours…
<?php session_start(); // Start Sessions for calculation
//…
Once you’ve added or edited a database table, it’s good to check that the change/addition was made… then either move on or show an error, etc.
Here’s how to do it with mysql_affected_rows().
Note, if the same data was submitted, i.e. a form with values filled in from the database was submitted…
Great to use once you passed values from $_GET to $_SESSION and don’t want the $_GET values to stay in the URL…. Also good if you’re processed data from a form… process and reload page…
// Redirect / reload
header('Location: /pathname/pagename/');
exit();
Using this script in an include just helps level the playing field…. ;-)
<?php
if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value…
Here’s a great little script that will back-up your database to a zipped .gz file and store it in a folder on your server….
<?php
// Set Vars
$dbname = 'DATABASE_NAME';
$dbhost = 'localhost';
$dbuser = 'USER_NAME';
$dbpass = 'PASS_WORD';
// Connect to DB
$conn = mysql_connect($…
Here’s another way to connect to the database:
// Connect with username, password, etc...
$link = mysqli_connect('localhost', 'userName', 'passWord');
if (!$link){
$error = 'Unable to connect to the database server.';
include 'error.html.php';
exit();
}
// Set Charset
if (!…
There are several methods of connecting to a database, here’s one example:
// Set the database access information as constraints
DEFINE ('DB_USER', 'userName);
DEFINE ('DB_PASSWORD', 'passWord');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'databaseName');
Use DEFINE to set your…
It’s a good idea to use $_SERVER['DOCUMENT_ROOT'] with includes as it makes life easier if moving a site onto a different development server… i.e.
<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; ?>