Please shed some light on this question!
I've got a mysql database and it has a few users(maximum 5) to be authenticated. I don't want to make a Mysql-Table user-authentication method for my own security reasons. Just the Top level mysql Users.
In my project there are two .php pages; index.php and connection.php; Within index.php a pop-up username and password Form appears and ask the user to input the username and password. By submitting the Form connection.php is called and it returns back to index.php file again to show more contents.
<?php
$link = mysql_connect("localhost", $_POST['UN'], $_POST['PW']);
mysql_select_db("databaseName", $link);
if($link){
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>
I want to be able to use $link variable in any page that includes the connection.php file and not make a new connection (It is obvious require("/connection.php") alone, in the bellow code below is silly).
<?php
require("/connection.php");
if(is_resource($link) != 'mysql link' || get_resource_type($link) != 'mysql link')
{
echo '<script>call-the-popup-form-again();</script>';
}else{Do-What-It-is-need-to-be-done();}
?>
As you see $link must act as a global variable to hold the connection link. Would you please explain how it is possible to implement this properly?
Thanks in advance