Hi everyone. I wanna start saying that I have been posting 4 Times on different sites and also twice on StackOverFlow, but didnt get some help as I am very new to php and mysql! But I really hope I can get some help fixing this script that I have tried to fix for a week now.
So in this script I am using the TEXTAREA that creates a table based on what users type in the textarea! So if user types "mike", then he will be assigned to a new URL called www.website.com/mike, and then a table will be created for that users so only HE is able to track and see his Visitors!
Right now the table is set to ""visitor_tracking" which makes everyone to see all the other users Info. Not fair! I decided to create another script and let users choose their own FOLDER NAME using the textarea, and that way enter the backend of their script. The textarea that I am using is assigned to a variable called $name, and the variable $name gets the texts from tghe textarea ID gname.
Thats how I managed to fix the first php file.
And then came the surprise.. I found 2 more php file that also includes the sql table "visitor_tracking" table and text. I desperately tried for 5 days to change it to $name, or somehow I did everything to use the text typed in the TEXTAREA to appear in the Database, and some how to make it affect other 2 php files too. But I failed. So all I need help for is to change the "visitor_tracking" and make the php files to read from the Textarea Variable $name..
I will attach all 3 php files, and the first is my main phpfile which is already fixed and done... I tried to use the $Session method, but failed! Now for 5 days I am totally lost.. This is the first and main php file which WORKS Great. "visitor_tracking" is changed to the variable $name, so you wont see the visitor_tracking in the first file...
<form action="" method="post" ><table width="400" border="0" cellspacing="0" cellpadding="5"> <tr> <td>Name </td> <td><input type="text" name="gname" id="text" value=""></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="submit" id="submit" value="Submit"></td> </tr></table></form><?PHPif (isset($_POST['submit'])) {$name = $_POST['gname'];mkdir("$name", 0777, true);chmod("$name", 0777);echo " ";echo "Conguradulations. Your new URL is sucessfully created.!";echo " ";echo " ";echo "Your new URL name is www.WEBSITE.com/$name"; }$dbhost = 'HOSTNAME';$dbuser = 'USERNAME';$dbpass = 'PASSWORD';$conn = mysql_connect($dbhost, $dbuser, $dbpass);if(! $conn ){ die('Could not connect: ' . mysql_error());}echo 'Connected successfully';$sql = 'CREATE TABLE ' . $name . '('. 'entry_id int(11) NOT NULL AUTO_INCREMENT, '. 'visitor_id int(11) default NULL, '. 'ip_address varchar(15) NOT NULL, '. 'page_name text, '. 'query_string text, '. 'timestamp timestamp NOT NULL default CURRENT_TIMESTAMP, '. 'PRIMARY KEY ( entry_id ), '. 'KEY visitor_id ( visitor_id , timestamp )) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;';mysql_select_db('DATABASENAME');$retval = mysql_query( $sql, $conn );if(! $retval ){ die('Could not create table: ' . mysql_error());}mysql_query($sql,$conn);?>
As you can see above in the SQL query I am using $name for the textarea with the ID gname
And I need to change the rest of the files like the first one, but I dont know how to make it READ from the first FILE.
The code below is what I added in the first php file to make it work and read from $name:
if (isset($_POST['submit'])) {$name = $_POST['gname'];
And I also changed the TABLE 'visitor_tracking' To:
CREATE TABLE ' . $name . '('.
Now here comes the other 2 php files, and I simply dont know how to read textarea from the first php files, or how to make the TEXT typed in TEXTAREA to be assigned to the
Here we go:
This is the 2nd Php file called "ip_tracker.php". (Need to change "visitor_tracking" table to variable $name used in my first php file:
<?php//define our "maximum idle period" to be 30 minutes$mins = 30;//set the time limit before a session expiresini_set ("session.gc_maxlifetime", $mins * 60);session_start();$ip_address = $_SERVER["REMOTE_ADDR"];$page_name = $_SERVER["SCRIPT_NAME"];$query_string = $_SERVER["QUERY_STRING"];$current_page = $page_name."?".$query_string;//connect to the database using your database settingsinclude("db_connect.php"); if($_SESSION["current_page"] != $current_page) { $sql = "INSERT INTO visitor_tracking (ip_address, page_name, query_string, visitor_id) VALUES ('$ip_address', '$page_name', '$query_string', '$visitor_id')"; if(!mysql_query($sql)){ echo "Failed to update visitor log"; } $_SESSION["current_page"] = $current_page; }}
And this is the 3rd Php file called "ip_report.php". ( Also want to change the "visitor_tracking" to variable $name used in my first php file:
<?phpinclude("db_connect.php");if($view == "all"){ //show all recent visitors $sql = "SELECT visitor_id, GROUP_CONCAT(DISTINCT ip_address) as ip_address_list, COUNT(DISTINCT ip_address) as ip_total, COUNT(visitor_id) as page_count, MIN(timestamp) as start_time, MAX(timestamp) as end_time FROM visitor_tracking GROUP BY visitor_id"; $result = mysql_query($sql); if($result==false){ $view = "error"; $error = "Could not retrieve values"; }} else { //show pages for a specific visitor $visitor_id = $_GET['id']; //rung $visitor_id through filter_var to check it's not an invalid //value, or a hack attempt if(!filter_var($visitor_id, FILTER_VALIDATE_INT, 0)){ $error = "Invalid ID specified"; $view = "error"; } else { $sql = "SELECT timestamp, page_name, query_string, ip_address FROM visitor_tracking WHERE visitor_id = '$visitor_id'"; $result = mysql_query($sql); } }function display_date($time){ return date("F j, Y, g:i a", $time); }?>
I have also tried to use the $_SESSION method and Session_Start, but Dont know why I cant make it work! Thats all, I really hope that my post is understandable! Thank you very much in advance, God bless, by Miguel!