Jump to content

BrainPill

Members
  • Posts

    123
  • Joined

  • Last visited

Everything posted by BrainPill

  1. Is it possible that there are cirumstances under which there is no output for the value ['browser'] or ['parent'] when using : get_browser(null, true); ? If so, can someone explain when and which situations cause that?
  2. I am working on a visitor counter. One way of storing the visitors in the database table is by getting the ip number. But I am not sure whether it is the right solution or not. I wonder if it is possible for a visitor to hide an ipnumber in a way that there is no ipnumber at all. Is that possible? What would you recommend to do to get a quite (real) unique visitor registration without users needing the possibilty to log in?
  3. I solved this meanwhile by changing the $browser variable into $some_var as I assume $browser is a reserved variable by php
  4. I have browscap installed this way: X:/wamp64/browscap/lite_php_browscap.ini If I use the following code: <?php $browser = get_browser(null, true); var_dump($browser); $brows_par = $browser['parent']; $browser = $browser['browser']; $version = $browser['version']; $platform = $browser['platform']; $dev_type = $browser['device_type']; $mobile = $browser['ismobiledevice']; $tablet = $browser['istablet']; ?> Then I get error messages for the last 5 variable settings error output: and for the other offsets same error message except the first 2. see the image for the var_dump value of $browser what causes the Illegal String Offset warning error message?
  5. I also solved it for batch files, by removing the parentheses
  6. I made a type mismatch in PHPmyadmin. The ; should not be included inside the double quotes. But still I can't understand the change of : - into a : û in the batch script. What causes this error?
  7. I solved this meanwhile. I used the timestamp column to make the query . I used this query : DELETE FROM `tab` WHERE `timestamp_col` < (NOW()– INTERVAL 10 MINUTE); I works only in the mysql command line interpreter. But I cant get it working in a batch script. Also in phpmyadmin it does not work. The error is in the minus sign. when running the batch script it shows a u with a caret like this û , and phpmyadmin gives error messages. Anyone any idea how to solve this?
  8. I also have a changed_on column with a timestamp value, is that also possible to use for the problem above?
  9. I want to have a mysql command that deletes a row based on the present time value. For example the column is like: first_time = 1550566437 (the time in the table.column is based on time() in php.) I would like to delete the rows that are older than one hour from the present time. I want to use mysql to delete it. My idea is that you can use now() from mysql and determine the difference in seconds (3600) Is that possible and how is it done?
  10. PHP does not give any errors. Or can I see it in phpmyadmin? This is the intended php/mysql code from the function I made. <?php // make OOP mysqli database connection $sql = 'SELECT Table_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = `yourdatabase_db` AND COLUMN_NAME LIKE `user_id` '; $stmt = $conn->prepare($sql) ; var_dump($stmt); $stmt->execute(); var_dump($stmt); //$stmt->bind_result($tabs); while ($stmt->fetch()) { var_dump($tabs); } printf("Error: %s.\n\r", mysqli_stmt_error($stmt)); printf("Error: %d.\n\r", mysqli_stmt_errno($stmt)); printf("Error: %s.\n\r", mysqli_stmt_sqlstate($stmt)); ?>
  11. I would like to fit this specific mysl query into php. I use prepared statements OOP for most queries if possible. Is there a way to get this executed: // database connection $sql = 'SELECT Table_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = `my_database` AND COLUMN_NAME LIKE `my_column` '; // do OOP prepared statements to get the columns I tried the mysql code in phpmyadmin and it worked properly, but in PHP no output. Please help.
  12. I meanwhile solved this by using var_export(). The output then is an exact render of the array in php.
  13. I would like to write the values of an array to a php file. I use fopen/fwrite/fclose to write the php file. I can define the array like this: But I get an array to string conversion error when the file is created. <?php $pagename = 'testpage2018a'; $data = 'abcd987654'; $fruit = array('apples','bananas','grapes'); $var5 = '$data'; $var6 = '$fruit'; $fopenvar = fopen('F:/www/yourdirectory/test/'.$pagename.'.php', 'w'); $page_cont = " <html> <body><center> <?php $var5 = '" . $data . "'; var_dump($var5); $var6 = '" . $fruit . "'; var_dump($var6); ?> </center> </body> </html> ?> How to solve this and write an array to a php file?
  14. Sorry I do not get it. Do you try to say that I need $_SESSION variables to make a website visitor unique? I suppose it is possible to store a user_id in a session var called $_SESSION['user_id'] = '12345abc'; but are you trying to say this is the proper solution for tracking website visitors? If an ipnumber has multiple devices connected to this single ipaddress I will not be able to distinguish them correctly. My assumption is that a browser cookie gives that possibility and for that reason I want to extract them.
  15. If I make a session cookie en store this in the database and I want to compare this database value with the value in the browser of the client, which kind of code do I need then to read the session cookie from the browser ? It is for a visitor counter. I don't know where to start exactly. Are there more possibilities? When I google it I get SE results telling that I have to use request headers in combination with CURL. I am not really familiar with it, so what is the best set up? I am building a visitor counter and besides ip number I would like to use a unique session_id alphanumeric that lasts until the user removes the cookie. Assuming this is the proper procedure I would like to figure out how it works and what code is used. Or is there an easier way to do this?
  16. I got that. It works terrific. Thanks for helping me out .
  17. This question is based on the table and class set up in my former posting. The difference is that I want to have a second function inside the class. The name of this second function is: check_amount () . I do not see any output or action at all in this function. I hope someone can help to make the example work. Database table: -- phpMyAdmin SQL Dump -- version 4.7.4 -- https://www.phpmyadmin.net/ -- -- Host: localhost:3306 -- Generation Time: Oct 04, 2018 at 08:42 AM -- Server version: 5.7.19 -- PHP Version: 7.1.9 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `test_fruit` -- -- -------------------------------------------------------- -- -- Table structure for table `fruit` -- DROP TABLE IF EXISTS `fruit`; CREATE TABLE IF NOT EXISTS `fruit` ( `rec_nr` int(2) NOT NULL AUTO_INCREMENT, `fruit_type` varchar(50) DEFAULT NULL, `amount` int(3) NOT NULL, `created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `changed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`rec_nr`,`created_on`,`changed_on`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -- -- Dumping data for table `fruit` -- INSERT INTO `fruit` (`rec_nr`, `fruit_type`, `amount`, `created_on`, `changed_on`) VALUES (1, 'apple', 5, '2018-10-04 06:01:48', '2018-10-04 06:01:48'), (2, 'strawberry', 20, '2018-10-04 06:01:48', '2018-10-04 06:01:48'), (2, 'banana', 15, '2018-10-04 06:02:54', '2018-10-04 06:02:54'), (4, 'grapes', 9, '2018-10-04 06:02:54', '2018-10-04 06:02:54'); COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; Script 1: <?php $amount = '' ; // 5, 20 , 15, 9 $fruit_type = 'grapes'; // grapes , apple, strawberry, banana $dbname = "test_fruit"; include 'fruit-class4a.php'; $object = new fruit_stock( '$fruit_type','$dbname'); $object -> get_fruit($amount, $fruit_type, $dbname); // $object ->get_fruit($amount, $fruit_type, $dbname)->check_amount($amount); var_dump($object); echo $object -> get_fruit($amount, $fruit_type, $dbname); ?> Script 2: <?php class fruit_stock { var $amount; var $dbname; public function get_fruit($amount, $fruit_type, $dbname) { global $amount; var_dump($fruit_type); var_dump($dbname); include 'login-test.php'; // login credentials $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // PREPARED if ($stmt = $conn->prepare("SELECT amount FROM fruit WHERE fruit_type = ? ; " )) { $stmt->bind_param('s', $fruit_type); // $stmt->execute(); $stmt->bind_result($amount); while ($stmt->fetch()) { var_dump($amount); return $amount; } } } public function check_amount($amount) { $amount = $amount + 1; var_dump($amount); return $amount; } } ?>
  18. But now I have another question. If I want to echo the $fruit_type , or make any kind of condition , outside the function but inside the class what should I do then ?
  19. I get it. This is the solution. $tel_wrg -> get_fruit($amount, $fruit_type); var_dump($tel_wrg); echo $tel_wrg -> get_fruit($amount, $fruit_type);
  20. to give in more variables. I dont understand, because only $amount is input. I got rid of the errors with adding $fruit_type to script 1 , but I need to understand for what reason php requires this?
  21. I have a challenge to solve regarding PDO and executing prepared statements inside a class. The way I made the script now is giving an error as output, though the outcome required is okay. The error type is: Fatal error: Uncaught ArgumentCountError: Too few arguments to function fruit_stock::get_fruit(), 0 passed in Could it be the error is caused because PHP requires that the execute() part should be defined or something like that? I really dont get what to do with it or with $stmt . . This are the scripts and the table so you can test it yourself. I'm curious how this is done. database table : -- phpMyAdmin SQL Dump -- version 4.7.4 -- https://www.phpmyadmin.net/ -- -- Host: localhost:3306 -- Generation Time: Oct 04, 2018 at 08:42 AM -- Server version: 5.7.19 -- PHP Version: 7.1.9 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `test_fruit` -- -- -------------------------------------------------------- -- -- Table structure for table `fruit` -- DROP TABLE IF EXISTS `fruit`; CREATE TABLE IF NOT EXISTS `fruit` ( `rec_nr` int(2) NOT NULL AUTO_INCREMENT, `fruit_type` varchar(50) DEFAULT NULL, `amount` int(3) NOT NULL, `created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `changed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`rec_nr`,`created_on`,`changed_on`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -- -- Dumping data for table `fruit` -- INSERT INTO `fruit` (`rec_nr`, `fruit_type`, `amount`, `created_on`, `changed_on`) VALUES (1, 'apple', 5, '2018-10-04 06:01:48', '2018-10-04 06:01:48'), (2, 'strawberry', 20, '2018-10-04 06:01:48', '2018-10-04 06:01:48'), (2, 'banana', 15, '2018-10-04 06:02:54', '2018-10-04 06:02:54'), (4, 'grapes', 9, '2018-10-04 06:02:54', '2018-10-04 06:02:54'); COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; Script 1: <?php // run class $amount = '20' ; include 'fruit-class1.php'; $tel_wrg = new fruit_stock('$amount'); $tel_wrg -> get_fruit($amount); var_dump($tel_wrg); echo $tel_wrg -> get_fruit(); ?> Script 2 : <?php // test classes class fruit_stock { var $amount; public $get_fruit; public function get_fruit($amount ) { var_dump($amount); var_dump($this); $servername = "your host"; $username = "your name"; $password = "your password"; $dbname = "test_fruit"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // PREPARED if ($stmt = $conn->prepare("SELECT fruit_type FROM fruit WHERE amount = ? ; " )) { $stmt->bind_param('i', $amount); // $stmt->execute(); $stmt->bind_result($fruit_type); while ($stmt->fetch()) { var_dump($fruit_type); } } } }
  22. Hello, I have the following issue with this dropdown menu. The menu is a side panel. Clicking on the option shows the desired page but, the problem is that the options in the submenus (level 2 and 3) jump away / dissappear one way or another. What I want to see as a result is: if is clicked on a submenu then the submenu is still visible. Is there someone who can give a solution about how to solve this. HTML PART: <?php if (!isset($_GET['menuquery'])){ $_GET['menuquery']=''; } ?> <html> <head> <meta charset="utf-8" /> <title>menu</title> <link rel="prefetch" href="http://"> <link rel="stylesheet" type="text/css" href="http://localhost/Begin/CSS/sidepanel/sidepanel-frm.css" media="screen" /> <title>Control Panel </title> </head> <body style="color: white;"> <div class="sidepanel_wrap"> <div class="pan_left"> <div style="height: 50px;"> <?php echo $_SERVER['HTTP_HOST']; ?> </div> <div class="sidenav"> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=home">Home</a> <button class="dropdown-btn">Level-1a <i class="fa fa-caret-down"></i> </button> <div class="dropdown-container"> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=level2a">Level-2a</a> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=level2b">Level-2b</a> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=level2c">Level-2c</a> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=level2d">Level-2d</a> </div> <button class="dropdown-btn">Level-1b <i class="fa fa-caret-down"></i> </button> <div class="dropdown-container"> <button class="dropdown-btn">Level-2b <i class="fa fa-caret-down"></i> </button> <div class="dropdown-containerl3"> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=level3a">level-3a</a> <a href="http://<?php echo $_SERVER['HTTP_HOST'] ?>/your_directory/menu-forum.php?menuquery=level3b">Level-3b</a> </div> </div> </div> </div> <div style="color: black;"> <?php var_dump($_GET['menuquery']); if (!isset($_GET['menuquery'])){ echo 'welcome'; } if (isset($_GET['menuquery'])){ if (($_GET['menuquery']) == 'home' ){ echo '<br>you clicked home !'; } if (($_GET['menuquery']) == 'level2a' ){ echo '<br>you clicked level2a !'; } if (($_GET['menuquery']) == 'level2b' ){ echo '<br>you clicked level2b !'; } if (($_GET['menuquery']) == 'level2c' ){ echo '<br>you clicked level2c !'; } if (($_GET['menuquery']) == 'level2d' ){ echo '<br>you clicked level2d !'; } } ?> </div> </div> <script> /* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */ var dropdown = document.getElementsByClassName("dropdown-btn"); var i; for (i = 0; i < dropdown.length; i++) { dropdown[i].addEventListener("click", function() { this.classList.toggle("active"); var dropdownContent = this.nextElementSibling; if (dropdownContent.style.display === "block") { dropdownContent.style.display = "none"; } else { dropdownContent.style.display = "block"; } }); } </script> </body> </html> CSS PART: body{background-color:#F3E5AB;} .sidepanel_wrap { width: 1880px; height: 860px; /*border: solid blue 2px;*/ display: flex; flex-direction: row; } .pan_left { display: inline-block; width: 235px; height: 860px; background-color: #67591F; color: #F3E5AB; } .main_panel_wrap { width: 1640px; height: 860px; background-color:#F3E5AB; } /* Fixed sidenav, full height */ .sidenav { width: 235px; height: 700px; position: relative; z-index: 1; top: 10; left: 0; background-color: #67591F; overflow-x: hidden; padding-top: 20px; } /* Style the sidenav links and the dropdown button */ .sidenav a, .dropdown-btn { padding: 6px 8px 6px 16px; text-decoration: none; font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans,serif; font-size: 14px; color: #93FFE8; display: block; border: none; background: none; width: 100%; text-align: left; cursor: pointer; outline: none; } /* On mouse-over */ .sidenav a:hover, .dropdown-btn:hover { color: #f1f1f1; } /* Add an active class to the active dropdown button */ .active { background-color: #4863A0; color: white; width:100%; } /* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */ .dropdown-container { display: none; background-color: #2B547E; padding-left: 0px; color: yellow; } .dropdown-containerl3 { display: none; background-color: #566D7E; padding-left: 0px; } /* Optional: Style the caret down icon */ .fa-caret-down { float: right; padding-right: 20px; color: #93FFE8; } /* Some media queries for responsiveness */ @media screen and (max-height: 450px) { .sidenav {padding-top: 15px;} .sidenav a {font-size: 18px;} }
  23. Great answer . I got it working they way you said it. Using the right definitions surely does clarify a lot. But one thing I could not get to work was the way of passing the $_GET query params with the iframe src. But that is a bit of topic maybe. Thanks anyway. Edit: I solved the query string passing with adding a piece of javascript code to the page that was called in the iframe.
  24. my idea is that the example you give is not what I want. In the OP I explained I wanted to make a piece of script that registers the number of impressions the text / banner link has. So at the moment a div (or iframe not sure what is the best way) loads on an external site. (not my site, but the site that links to me) I want some code that counts the download and send this information towards a page on my server where I use PHP/mysql to store the number in my database.table. The visitor should not have to click (yet) so before the click the div has loaded and that's what I would like to measure. The more I try to grasp this set up , the more I become convinced it can not be done with PHP but rather with javascript. Maybe it is possible, but I would like an easy set up. So everyone who wants to link towards my site should be able to easily copypaste some code and paste it in. This makes me think javascript is the best solultion. Not 100% sure so that's why I wanted to ask it here. So if these impressions cant be measured with php then let me know and I go on in javascript.
×
×
  • Create New...