Jump to content

BrainPill

Members
  • Content Count

    34
  • Joined

  • Last visited

Community Reputation

1 Neutral

About BrainPill

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. BrainPill

    get session cookie value from the browser

    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.
  2. BrainPill

    get session cookie value from the browser

    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?
  3. BrainPill

    how to use a second function inside a class?

    I got that. It works terrific. Thanks for helping me out .
  4. 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; } } ?>
  5. 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 ?
  6. 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);
  7. 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?
  8. 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); } } } }
  9. 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;} }
  10. BrainPill

    textlink/banner outside own server possible with PHP?

    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.
  11. BrainPill

    textlink/banner outside own server possible with PHP?

    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.
  12. BrainPill

    textlink/banner outside own server possible with PHP?

    This only works when a user clicks the link. But that is not what I want. I want to know the download, so I assume javascript is moreoften used. I am not really familiar with javascript. What is the easiest and least restricted / blocked way of doing it in AJAX/Javascript/jquery?
  13. BrainPill

    textlink/banner outside own server possible with PHP?

    okay but in what way can I count the number of downloads of an html element? Can that be done with HTML/PHP or is another language needed?
  14. Hello I'm facing a problem I cant really solve. I want to place a backlink in the shape of either a textlink or an img banner outside my own server. (for instance inside an iframe) I want to be able to track download impressions and referrer clicks. Can this be done with php or not? It seems technically not possible to place php on someone else's server. What would you recommend?
  15. BrainPill

    serial number and divide it over multiple database cols

    Do you know and example online about how to do this?
×