Jump to content

Search the Community

Showing results for tags 'PHP'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 932 results

  1. terrordinky

    From Mysql To Mysqli but gives error's

    Hello people, Im stuck for a long time, I have an what older login system on my site but it had mysql but now i wanted to upgrade it to mysqli. I've came litlle by litlle bit of searcing this far but it still got error's. I really want it to work again beacause i use it on all my sites. Code: <?php // Een beveiliging om te voorkomen dat men in je header.php probeert te openen. if(basename($_SERVER['PHP_SELF']) == "header.php") { header("Location: index.php"); } // Configuratie laden include_once('config.php'); // We maken eerst een classe aan class login { // Variabelen private $loginsessie = false; public $fouten = ""; private $gebruikers_info = array(); public $database_velden = array(); private $recheck = 0; // Deze functie wordt aangeroepen bij het laden van de classe public function __construct() { // maak verbinding met de database, als het niet lukt breek het af $con = mysqli_connect(mysql_host, mysql_user, mysql_password, mysql_database) or die(mysqli_error($con)); // mysqli_select_db(mysql_database, $verbinding) or die (mysqli_error($con)); // Controlleren op een login sessie $this->check_session(); // De loguit actie koppelen aan de end_session functie if(isset($_GET['actie']) && $_GET['actie'] == 'uitloggen' && $this->loginsessie === true) { $this->end_session(); } } // Init functie public function init() { // Controlleren op een POST request, wanneer er nog geen loginsessie is if($_SERVER['REQUEST_METHOD'] == 'POST') { /* was eerst if($_SERVER['REQUEST_METHOD'] == 'POST' && $this->loginsessie===false) {*/ if(isset($_POST['actie'])) { switch($_POST['actie']) { case 'login': $this->controleer_gegevens(); break; case 'registreer_gebruiker': $this->registreer_gebruiker(); break; } } } } // Functie om het ip adres op te vragen public function get_ip() { if (isSet($_SERVER)) { if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) { $realip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) { $realip = $_SERVER["HTTP_CLIENT_IP"]; } else { $realip = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $realip = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $realip = getenv( 'HTTP_CLIENT_IP' ); } else { $realip = getenv( 'REMOTE_ADDR' ); } } return $realip; } private function registreer_gebruiker() { if(isset($_POST['actie']) && $_POST['actie'] == 'registreer_gebruiker') { $velden = array(); if(!is_array($this->database_velden) || !count($this->database_velden)) { die("FOUT: Geen velden opgegeven."); } // Alle velden uit de array doorlopen foreach($this->database_velden as $veld) { $veld = split(':', $veld); // Veldnaam $veld_naam = $veld[0]; $velden[$veld_naam] = $_POST[$veld_naam]; // Veld instellingen $veld_instellingen = split('\|', $veld[1]); foreach($veld_instellingen as $instelling) { if($instelling == 'verplicht' && empty($velden[$veld_naam])) { // Controlleer of het veld is ingevuld $this->fouten .= "- Het veld '". $veld_naam ."' is verplicht<br />"; } elseif($instelling == 'md5') { // Codeer naar md5 $velden[$veld_naam] = md5($velden[$veld_naam]); } elseif(substr($instelling, 0, 3) == 'min') { // Controlleer minimum stringlengte if(strlen($velden[$veld_naam]) < (int) substr($instelling, 4)) { $this->fouten .= "- Het veld '". $veld_naam ."' is te kort.<br />"; } } elseif(substr($instelling, 0, 3) == 'max') { // Controleer maximum stringlengte if(strlen($velden[$veld_naam]) > (int) substr($instelling, 4)) { $this->fouten .= "- Het veld '". $veld_naam ."' is te lang.<br />"; } } elseif(substr($instelling, 0, 2) == "==") { if($velden[$veld_naam] != $_POST[substr($instelling, 2)]) { $this->fouten .= '- De velden '. $veld_naam .' en '. substr($instelling, 2) .' komen niet overeen.<br />'; } } elseif($instelling == "avatar") { $velden[$veld_naam] = ('http://habmoon.org/status/habbie?habbie='.$_POST["gebruikersnaam"].'&direction=4&head_direction=3&action=wlk&gesture=sml&size=b'); } elseif($instelling == 'uniek') { $q = mysqli_query($this->con,"SELECT ". $veld_naam ." FROM gebruikers WHERE ". $veld_naam ." = '". mysqli_real_escape_string($this->con, $velden[$veld_naam]) ."' "); if(!$q) { $this->fouten .= '- Er is een MySQL fout opgetreden <br />'; } else { if(mysqli_num_rows($q)) { $this->fouten .= 'De inhoud van veld '. $veld_naam .' bestaat al<br />'; } } } elseif($instelling == 'email') { // Controleer email if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $velden[$veld_naam])) { $this->fouten .= "- Het email is incorrect.<br />"; } } } } if(!$this->fouten) { // SQL genereren $SQL = "INSERT INTO gebruikers "; $SQL_TMP = ""; foreach($velden as $key=>$value) { $SQL_TMP .= ", ". $key ." = '". mysqli_real_escape_string($this->con, $value) ."' "; } // Eerste komma weghalen $SQL .= "SET ".preg_replace("#^,{0,1}#", '', $SQL_TMP); if($SQL_TMP && mysqli_query($this->con,$SQL)) { header("Location: ../index.php"); } else { $this->fouten = "Er is een MySQL fout opgetreden."; /* om te debuggen gebruik: die(mysqli_error($con)); */ } } } } // Functie om gegevens te controleren private function controleer_gegevens() { // Kijken of we het juiste formulier gebruiken if(isset($_POST['actie']) && $_POST['actie'] == 'login') { // Gegevens van formulier opvragen en escapen tegen mysql injectie $gebruiker = mysqli_real_escape_string($this->con, $_POST['gebruikersnaam']); $wachtwoord = mysqli_real_escape_string($this->con, $_POST['wachtwoord']); // Kijken of we MD5 moeten gebruiken (zie configuratie bestand) if(login_password_md5===true) { $wachtwoord = md5($wachtwoord); } // Kijken of de gegevens correct zijn $query = mysqli_query($this->con,"SELECT * FROM gebruikers WHERE gebruikersnaam = '". $gebruiker ."' AND wachtwoord = '". $wachtwoord ."'"); if(mysqli_num_rows($query)) { // Array gebruikersinfo maken $this->gebruikersinfo = array(); $this->gebruikersinfo['info'] = mysqli_fetch_array($query); // Start sessie return $this->start_session(); } else { // Kijken wat er mis ging: if(mysqli_error($this->con)) { $this->fouten = "Er is een mysql fout opgetreden."; } else { $this->fouten = "Gebruiksnaam en/of wachtwoord is incorrect."; } } } } // Functie om de sessie te controlleren private function check_session() { // Controleren op cookie if($this->recheck>=3) { $this->fouten = "Er is een ongeldige cookie sleutel gevonden die niet kon worden verwijderd."; return false; } if(isset($_COOKIE['sid']) && !empty($_COOKIE['sid'])) { // Er is een niet-lege cookie $sid = mysqli_real_escape_string($this->con, $_COOKIE['sid']); // Controleren of sleutel en ip aanwezig zijn in database $query = mysqli_query($this->con,"SELECT * FROM logins WHERE sid = '". $sid ."' AND ip = '". $this->get_ip() ."'") or die("Er is een fout opgetreden."); if(mysqli_num_rows($query)) { $f = mysqli_fetch_array($query); // Gegevens uit database ophalen $query = mysqli_query($this->con,"SELECT * FROM gebruikers WHERE id = '". $f['uid'] ."' "); if(mysqli_num_rows($query)) { $this->loginsessie = true; $this->gebruikersinfo = array(); $this->gebruikersinfo['info'] = mysqli_fetch_array($query); } } } else { // Er is een ongeldige sleutel gevonden, laten we die eens verwijderen $secondes = login_session_time * 3600; setcookie("sid", "", time()-$secondes, "/"); $this->recheck = $this->recheck + 1; } } // De functie om de login sessie te starten private function start_session() { // Unieke sleutel maken $this->gebruikersinfo['sleutel'] = md5(rand(0,99999999999).date("dmyhis")); // Informatie invoegen in database $info = $this->gebruikersinfo['info']; $SQL = "INSERT INTO logins "; $SQL .= "SET uid = '". mysqli_real_escape_string($this->con, $info['id']) ."' "; $SQL .= ", sid = '". mysqli_real_escape_string($this->con, $this->gebruikersinfo['sleutel']) ."' "; $SQL .= ", ip = '". mysqli_real_escape_string($this->con, $this->get_ip()) ."' "; $SQL .= ", datum = NOW() "; mysqli_query($this->con,$SQL) or die("Error: kon niet inloggen."); // Secondes maken van uren, zie configuratie bestand $secondes = login_session_time * 3600; setcookie("sid", $this->gebruikersinfo['sleutel'], time()+$secondes, "/"); // Verversing header("Location: ".$_SERVER['REQUEST_URI']); } private function end_session() { // index.php?actie=uitloggen // Verwijder sessie mysqli_query($this->con,"DELETE FROM logins WHERE sid = '". $_COOKIE['sid'] ."' AND ip = '". $this->get_ip() ."'") or die("Er is een fout opgetreden."); // verwijder cookie $secondes = login_session_time * 3600; setcookie("sid", "", time()-$secondes, "/"); // Redirect $url = str_replace("actie=uitloggen", "", $_SERVER['REQUEST_URI']); // haal de actie weg header("Location: ".$url); } // Functie om gegevens op te vragen public function get_login_info($wat=false) { // Is er iets aanwezig? if(!$this->loginsessie || !count($this->gebruikersinfo)) { return false; } else { if($wat==='alles') { return $this->gebruikersinfo['info']; } elseif(isset($this->gebruikersinfo['info'][$wat])) { return $this->gebruikersinfo['info'][$wat]; } else { return true; } } } } // Class starten $login = new login(); $login->database_velden = array( /* Velden waarvan de value in de database komt. Plaats die in de database en formulier. Syntax: veldnaam:instellingen Instellingen scheiden met '|'. Instellingen: 'verplicht': [string] Verplicht veld. 'min=int': [int] Minimum aantal karakters dat is vereist. 'max=int': [int] Maximum aantal karakters dat is vereist. '==veldnaam': [string] waarde van dit veld moet overeenkomen met 'veldnaam'. 'md5': [string] Codeer met md5. MOET als laatste. */ 'gebruikersnaam:verplicht|uniek|min=3|max=15|', 'rank:max=15|', 'email:max=100|email|', 'avatar:max=100|avatar|', 'wachtwoord:verplicht|min=3|max=16|==wachtwoord2|md5|' /* was eerst 'wachtwoord:verplicht|min=3|max=16|==wachtwoord2'*/ ); $login->init(); ?> Error: Notice: Undefined property: login::$con in C:\xampp\htdocs\Admin\header.php on line 157 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Admin\header.php on line 157 Notice: Undefined property: login::$con in C:\xampp\htdocs\Admin\header.php on line 158 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Admin\header.php on line 158 Notice: Undefined property: login::$con in C:\xampp\htdocs\Admin\header.php on line 166 Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Admin\header.php on line 166 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\Admin\header.php on line 167 Notice: Undefined property: login::$con in C:\xampp\htdocs\Admin\header.php on line 176 Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Admin\header.php on line 176
  2. iwato

    Chaining PHP Class Methods

    BACKGROUND: While implementing Peppe Occhi's CRON Scheduler I have come across several lines of code that I am not entirely familiar. In particular I am concerned with the following: $scheduler->php('script.php')->hourly(); found under the heading Schedules execution time. It appears to be of this format $some_instance->some_methodA(arguments)->method_B(arguments); QUESTION: Is the above expression equivalent to the following: $some_instance->some_methodA(arguments); $some_instance->method_B(arguments); In other words, the following is correct: $scheduler->php( 'path_to_folder/script.php', 'path_to_php_version/ea-php72', ['-c' => 'ignore','--merge' => null,], 'file_name' ); $scheduler->hourly(); Please advise. Roddy
  3. Sigmahokies

    get data (checkbox) from iframe

    Hi everyone, is it possible to collect data such as checkbox and radio inside iframe when push button outside of iframe? or require to method of post inside iframe?
  4. Sigmahokies

    checkbox and paginate page

    Hi everyone, I'm trying to create the look like "paginate data page", but it is not. I set up the file to insert in website by iframe, but I need to find a way to make clicked data like click the checkbox, then click on next, go to next file in iframe, then come back, stay checked in checkbox. Do you understand what I mean? I'm not fluent in English, my prime is American Sign Language.
  5. iwato

    A Nested Class? Or, Inheritance?

    BACKGROUND: I am creating a custom class for use with PHPMailer that will hopefully eliminate redundancy in its application and even facilitate my use of the class. One of my questions deals with inheritance and the other has to do with scope. My current use of PHPMailer is quite simple. It consists of a folder containing four files: three of these are PHP class definitions and one of them is an autoloader. PHPMailer is called in the following manner: require_once '../../../PHPMailerAutoload.php'; $mail = new PHPMailer; Once the instance $mail has been created I have access to a large number of public functions that I have thought to consolidate into a single class of my own making called PHPGlobalMailer. My construction of this class appears awkward, and I would like to solicit your feedback in an attempt to remove its clumsiness. class PHPGlobalMailer { private $mail; private static $char_set = 'UTF-8'; private static $smtp_debug = 0; // SMTP::DEBUG_OFF (0): Disable debugging (default). // SMTP::DEBUG_CLIENT (1): Output messages sent by the client. // SMTP::DEBUG_SERVER (2): as 1, plus responses received from the server. // SMTP::DEBUG_CONNECTION (3): as 2, plus more information about the initial connection (used to diagnose STARTTLS failures. // SMTP::DEBUG_LOWLEVEL (4): as 3 (Verbose). private static $debug_output = 'html'; // 'echo': Plain text output (default). // 'html': Browser output. // 'error_log': Output to php.ini configured error.log. // function($str, $level) {echo "Debug Level: " . $level; "Error Message: " . $str;} private static $hostserver = '...'; private static $server_port = ...; private static $smpt_auth = 'true'; private static $mail_account_name = '...'; private static $mail_account_password = '...'; private static $from_mail_address = '...'; private static $from_mail_name = '...'; private static $reply_to_address = '...'; private static $reply_to_name = '...'; public $email = ''; public $name = ''; public $subject = ''; public $html_message = ''; public $alt_message = ''; public function __construct($email, $name, $subject, $html_message, $alt_message) { if ($this->mail new PHPMailer) { $this->mail->CharSet=self::$char_set; $this->mail->isSMPT(); $this->mail->SMTPDebug = self::$smpt_debug; $this->mail->Debugoutput = self::$debug_output; $this->mail->Host = self::$hostserver; $this->mail->Port = self::$server_port; $this->mail->SMPTAuth = self::$smpt_auth; $this->mail->Username = self::$mail_account_name; $this->mail->Password = self::$mail_account_password; $this->mail->setFrom(self::$from_mail_address, self::$from_mail_name); $this->mail->addReplyTo(self::$reply_to_address, self::$reply_to_name); $this->mail->addAddress($this->email, $this->name); $this->mail->Subject = $this->subject; $this->mail->msgHTML($html_message); $this->mail->altBody = $alt_message; } else { echo "Error: Failure to create new PHPMailer instance."; } } public function get_character_set() { return self::$char_set; } public function set_character_set($char_set) { self::$char_set = $char_set; } public function get_smtp_debug() { return self::$smtp_debug; } public function set_password($smtp_debug) { self::$smtp_debug = $smtp_debug; } public function get_debug_format() { return self::$debug_output; } public function set_debug_format($debug_output) { self::$debug_output = $debug_output; } public function get_debug_format() { return self::$debug_output; } public function set_debug_format($debug_output) { self::$debug_output = $debug_output; } public function get_mail_instance() { return $this->mail; } } The AWKWARDNESS 1) In order to make it work I must include PHPMailerAutoload.php file. Is there someway that I could avoid this, say through inheritance? 2) Notice that I am creating an instance of PHPMailer inside my class and then using the instance's public functions to modify it. Is this proper? If not, what would be a more appropriate way of constructing my class. 3) I am concerned that adjustments to an instance of PHPGlobalMailer will affect other instances created in a similar manner. For example, were I to change the value of $smpt_debug for a particular instance of PHPGlobalMailer would it not effect the value of that same parameter for other instances of PHPGlobalMailer? In effect, I would like full control of each instance, but still maintain constancy with regard to the $account_name and $account_password and other values across all instances. Could you please comment on each of three points. Roddy
  6. warrens0017

    Line Break in email not working

    Hi everyone, I am running into an issue when I am sending out emails using the mail() function. What I am trying to do is on one page, there is a text area that enters information into a form and sends it to another php to process. Here is the form: <form method='POST' action='../home/contact-send-email.inc.php'> <div class='input_form'> <input type='hidden' name='cid' value='".$rowcon['cid']."'><br> <input type='hidden' name='from' value='".$_SESSION['email']."'><br> <input type='hidden' name='email' value='".$rowcon['email']."'><br> <input type='text' name='subject' placeholder='Subject'><br> <textarea style='width: 103.5%; height: 500px; resize: none;' type='text' name='message' placeholder='Message'></textarea><br> <button type='submit'>Send Mail</button> </div> </form> Now with the text area, I want it to allow line breaks. The issue I am running into now is that when I send email out, I am getting the text but were I put the line breaks, there is a \r\n in text. Here is the mail process php: <?php include '../inc/dbh.php'; $from = mysqli_real_escape_string($conn, $_POST['from']); $msg = mysqli_real_escape_string($conn, $_POST['message']); $to = mysqli_real_escape_string($conn, $_POST['email']); $subject = mysqli_real_escape_string($conn, $_POST['subject']); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type:text/html; charset=UTF-8\r\n"; $headers .= "From: ".$from."\r\n"; $headers .= "X-Mailer: PHP 5.x\r\n"; $txt = nl2br($msg); mail($to, $subject, $txt, $headers); ?> So quick over view: When I send an email out using this code and there are line breaks in there, where the line breaks are happening, in the email there is \r\n instead of the line break.
  7. BACKGROUND: Recently I had occasion to make a search on my own website using the Newsletter search engine. What I discovered was the most bizarre of behaviors. I could perform one search in Japanese and then no more. In other languages such as French, German, and English I could perform as many searches as I liked -- even repeating the same words more than once -- and I always I was able to produce the expected result. Mind you, this bizarre one-find-stop--all-further-finds behavior in the Japanese language was not the case when I first installed my search engines. Now, I have checked my PHP error.log file and found nothing related to this problem. I have also checked that the parameter value of the AJAX call is being properly passed; here too there is no unusual behavior. This bizarre behavior was not always the case. It appears to have begun taking place all of its own. Any ideas? Roddy
  8. BACKGROUND: While I continue to struggle with my wget problem, I would like to reaffirm a discussion that we had already two or three months ago about the use of hash marks in an HTTP Request query string. Please consider the following HTTP Request copied from a Matomo API request generated by Matomo. I only initiated the request, I did not create it. https://www.nudge.online/_utilities/php/matomo/index.php ?module=CoreHome &action=index &idSite=1 &period=day &date=yesterday #?idSite=1 &period=day &date=yesterday &category=General_Actions &subcategory=Actions_SubmenuSitesearch Is it not likely that the above request is one request riding piggy-back on another that upon arrival get split and are made into two separate requests? If my interpretation is indeed accurate, then why make the initial request at all, as it appears to add no new information. Why not just write and send the following: https://www.nudge.online/_utilities/php/matomo/index.php ?module=CoreHome &action=index &idSite=1 &period=day &date=yesterday &category=General_Actions &subcategory=Actions_SubmenuSitesearch Any ideas? Roddy ps: I know it seems silly to have to post these questions at W3Schools, but this reflects the desert of support that Matomo offers while making its software free to the general public. Although it is surely true that beggars should not be choosers, how can one possibly expect to promote one's software without providing even the most minimal support needed to make it work!
  9. BACKGROUND: Having upgraded my server I now have full command of the UNIX terminal. Although a good thing, my first attempt to make use of it has failed. The following code was used to access the Matomo application which resides on the same Lunarpages VPS server as the PHP routine that calls it -- albeit from a different domain name. The CODE: <?php ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log'); ini_set('html_errors', 0); ini_set('display_errors', 0); error_reporting(E_ALL); exec('wget --http-user=[...] --http-password=[...] -P /tmp/ -p -k https://.../index.php?module=Widgetize&action=iframe&containerId=GoalsOverview&widget=1&moduleToWidgetize=CoreHome&actionToWidgetize=renderWidgetContainer&idSite=1&period=day&date=yesterday&disableLink=1&widget=1&token_auth=[...]'); ?> When I examine the Response panel in the Network Menu of Firefox, nothing appears. This said PHP does not complain and the Headers panel returns an HTTP Request code of 200. When I run the same wget command in terminal I am able to generate an HTML file, but the contents tells me that the Matomo API responsible for generating the desired widget is not accessible. The error message reads, Any suggestions? Roddy
  10. JJJorgensen

    Customized member birthday greeting

    I want to create a customized birthday greeting for my members once they log in. Requirements: If they log in +/- 7 days from their birthday, show custom greeting in a pop up box only once. - so if they log in every day they only see the greeting once... Show the greeting on their birthday (again or new custom message) if they log in ON their birthday. If they don't log in on their birthday or the +/- 7 days, show a Sorry we missed you, birthday greeting the next time they log in. I can handle the logic part of this, i.e. BDate +/- 7, etc. I just don't know how to keep track of the log ins. I tried searching on the web but I kept getting results specific to development platforms, like WordPress or Wix. I want to write my own code. I assume it should be handled with a counter? on the log in. Or do I create a new line in the membership table for this log in? Can someone point me to some documentation or an example? I don't mind researching it.
  11. Greetings to all the users and administrators of w3scools invisionzone forum. I would love to get some constructive criticism on this web development tutorial site namely webtrickshome. It's been around for slightly more than a year but I redesigned it recently. Any feedback regarding the design and contents would be highly appreciated. Thankyou
  12. warrens0017

    Getting information from Database

    Hello everyone, I am running into an issue now to where I am trying to get information from a database but it is only happening when there is an apostrophe in the text. Meaning things, getting the data from the database, there is a word with an apostrophe in it. I get all the information from the start up to the point where the apostrophe is at. For example: The cat can't jump over water. What I will get is this: The can can Then I don't get the rest of my data. Here is the code I am dealing with. Any help would be great. $id = $_POST['id']; $title = $_POST['title']; $writer = $_POST['writer']; $description = $_POST['description']; $date_created = $_POST['date_created']; $message = $_POST['message']; echo "By: ".$writer; echo "Title: ".$title; echo "Description: ".$description; echo "Message: ".nl2br($message);
  13. Hi everyone, I am still learning changing PHP by mysqli to PDO. I'm not get used with PDO because it is little complex to understand, but maybe few weeks I will understand how PDO works. Now, I am trying to make redirect with type account in website and database. I am trying to identify type of three - administrator, license, and scorer page. I set up the test to make it work, seem it went dead end, it won't go to admin or license or scorer page. What did I do wrong? maybe something is missing. here my code: <?php /** * Created by PhpStorm. * User: Gary.Taylor * Date: 7/5/2018 * Time: 10:10 PM */ session_start(); require('access.php'); if(isset($_POST['submitted'])) { $username = $_POST['username']; $password = $_POST['password']; if($username && $password) { $login = $GaryDB->prepare("select username, password, Administrator from account Where username = '.$username.' and password = '.$password.' and Administrator = X"); $login->execute(); $count = $login->fetch(); if($count == 1) { $_SESSION['username'] = $username; header('location:admin.php'); } } elseif ($username && $password) { $login = $GaryDB->prepare("select username, password, License from account Where username = '.$username.' and password = '.$password.' and License = X"); $login->execute(); $count = $login->fetch(); if($count == 1) { $_SESSION['username'] = $username; header('location:license.php'); } } elseif ($username && $password) { $login = $GaryDB->prepare("select username, password, Scorer from account Where username = '.$username.' and password = '.$password.' and Scorer = X"); $login->execute(); $count = $login->fetch(); if($count == 1) { $_SESSION['username'] = $username; header('location:scorer.php'); } } else{ header('location:denied.html'); } }
  14. iwato

    Working with the Matomo Cookie

    OBJECTIVE: Suppress my site's splash panel for repeat visitors using a mechanism similar to the one that I use to suppress the panel for visitors whose viewports are too small to handle it properly. BACKGROUND: As I have instructed Matomo not to recognize me when I access the application I have no way of testing whether my code is working. According to a friend who has experimented with his own computer it does not. Although I am able to retrieve the cookie set by Matomo, I am now uncertain about how to handle it. NOTE: The cookie that Matomo appears to set is not set until the page has The COOKIE Sent by Matomo Array ( [_pk_id_1_28d8] => b1dccabc0123a611.1529214805.24.1530731060.1530731060. [_pk_ses_1_28d8] => * ) The PHP that Recovers the COOKIE and Assigns It to a Javascript Variable if (isset($_COOKIE['_pk_id_1_28d8'])) { $cookie_set = 1; } The JAVASCRIPT on the Same Page as the PHP var cookie_set = <?php echo $cookie_set;?>; The JAVASCRIPT on a Loaded Script Page that Controls the Splash Panel if ((!refer_type && !navtype && (viewportWidth > 360)) || !cookie_set) { [the code that sets the splash panel] } QUESTION: Can you see anything in the above logic or design that could be showing the splash panel when it is not desired? Roddy
  15. iwato

    A Matomo Bulk HTTP Request

    REQUEST: Please compare the following PHP code with the intended result, and if possible, say why only the last urls[ ] parameter is being read. BACKGROUND: The following code is part of a successfully received and partially processed HTTP POST Bulk Request to the Matomo application. Both of the called methods -- namely, Events.getCategory and Events.getAction -- have been tested separately and are perfectly functional. Further, the Matomo application reports no dysfunction, and there are no warning, notices or other indicated sources of foul coding in the PHP log file. $result = ''; $query_str = ''; $i = 0; $token_auth = '...'; function set_url_request($method, $params) { $request = "method=$method"; foreach ($params as $param) { $request .= "&" . $param; } return rawurlencode($request); } $url = "https:/.../index.php"; $url .= "?module=API"; $url .= "&method=API.getBulkRequest"; $url .= "&format=json"; $url .= "&token_auth=$token_auth"; foreach ($_POST['methodName'] as $method) { $method = filter_var($method, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); if ($method == '_getCategory') { $method = "Events." . substr($method, 1); $params = array("idSite=1","period=year","date=today","format=json"); $query_str = set_url_request($method, $params); $url .= "&urls[$i++]=" . $query_str; } if ($method == '_getAction') { $method = "Events." . substr($method, 1); $params = array("idSite=1","period=year","date=today","format=json"); $query_str = set_url_request($method, $params); $url .= "&urls[$i++]=" . $query_str; } } The above is suppose to yield code formatted in a manner similar to the following HTTP request. Obviously, I have modified it in important ways, Important, however, is that the &urls[0] request appears to be ignored. https://demo.piwik.org/index.php ?module=API &method=API.getBulkRequest &format=json &urls[0]= method%3dVisitsSummary.get %26idSite%3d3 %26date%3d2012-03-06 %26period%3dday &urls[1]= method%3dVisitorInterest.getNumberOfVisitsPerVisitDuration %26idSite%3d3 %26date%3d2012-03-06 %26period%3dday Roddy
  16. Hey guys, EDIT: I have been looking on the web to find a way to automatically download a pdf when a page opens, without user having to click a link. However, no solution found (at least which i can get to work...) Help is much appreciated!! Thanks guys!
  17. mysteriousmonkey29

    Interactive web comic aggregator general design?

    Hello, I am currently in the middle of creating a web comic aggregation website. So far, I have written a PHP-based RSS reader that grabs the image source links and publication dates for various web comics from their RSS feeds, and uses this to update a MySQL database. This RSS reader/database updater is configured to run once every several hours and update the database with any new comics it finds. It seems to be working fine, and now I am starting to work on the front end of the website, which needs to grab this information from the ever-growing database, and display it in a user-friendly and interactive format. I wrote the database updater in a fairly procedural way, because it didn't strike me as something that lent itself very much to object-oriented development. However, the front end of the website does strike me as something that I can save myself a lot of time on by coming up with a decent object oriented design first. Unfortunately, I don't have a lot of experience in this, so I thought I would look online for suggestions. So far, I have decided specifically what I would like the front end to do, and have come up with 2 possible approaches to designing it, but am unsure about both. Here's what I would like it to do: (To clarify, when I say the phrase "comic strip," I'm referring to a whole strip like XKCD, Dilbert, the far side, etc., and when I say the phrase "comic," it refers to an individual comic within a comic strip, i.e. the Dilbert comic for 8/30/2016). I would like my webpage, by default, to display a vertically stacked list of the latest comic images from each comic strip in the database. For customization, I want a comic strip control panel, which allows users to decide which comic strips are enabled/disabled, and in what order they are displayed. I would like each comic image to appear between text denoting the name/author of the strip and an individual set of buttons that allows the user to go forward and backward through the archived comics, and also to adjust the size/scaling of the image. Finally, I would like a similar but generalized set of buttons that allows the user to control all the comic strips in the same fashion, but at once. Based on my basic understanding of object oriented programming, and the design approach suggested in this stack overflow answer: http://stackoverflow.com/questions/1100819/how-do-you-design-object-oriented-projects, I came up with one possible design: Two classes: 1) a comic strip class that contains attributes like the comic strip's name, ID number (from my database), enabled/disabled status, and current comic to display (an object of the next class), in addition to functions to get and set each of these variables, 2) a comic class that contains attributes like the image source link, publication date, and scaling percentage, in addition to functions to get and set each of these variables Then the main webpage would contain a comic strip control panel and general comic control panel as described in the desired functionality. In addition, it would contain an array of individual comic control panels, and an array of div tags (or a similar tag), which would be displayed vertically stacked and alternating along with the comic strip names in plain text. Finally, there would be functions for updating comic and comic strip object information from the database, and functions for updating the div tag content for comic display based on the comic object information. All the functions would be called using JavaScript/Ajax from the appropriate buttons. However, I was unsure about this design, so I asked a friend, who suggested that I use a model-view-controller design pattern, which I guess is popular in web development because its potential for separating all the various languages. After reading about this online, I have come up with a possible alternative design: Model: PHP, an array of comic strips, including name and ID number, active/inactive status, and current comic image URL/publishing date View: PHP generated HTML/CSS, as described before, a comic strip control panel for enabling/disabling and ordering, a vertically stacked list of comic strip names, constituent comic images, and individual control buttons, and a general set of buttons for controlling all enabled comics at once Controller: PHP/MySQL, a function to update order and active/inactive comic strip status, a function to update a given comic strip's current comic information, and a function to update all comic strips' current comic information at once As I understand it, the controller functions would be called upon user input into the view (clicking the buttons), which would then update the information stored in the model, and then somehow that would trigger a refresh of the view based on the new model information. I am worried I may have missed something in each of these designs (especially the first one), and unsure about the potential merits of one versus another. I was also wondering if it might be possible to combine the two somehow. Does anyone have any suggestions? Help would be much appreciated
  18. Hello, Please help, how to implement the Depth First Search algorithm into PHP MyQsli. I have a table: - problem - because - solution The DFS diagram I attached. thank you
  19. Is it possible to use this lightbox code with multiple galleries? At the moment, when using it with different galleries, lightbox will pop up, but it only show first gallery, and the others won't display. I have implemented this lightbox code with my PHP code and for the first gallery, everything is fine, but when I click others, only those gallery thumbnails will show up, but the currentSlide isn't and I understand that code changes only in the first gallery. My code: <div class="row"> <div class="row-inner" id="ajax-posts"> <?php while( $refs->have_posts() ): $refs->the_post(); // get_template_part('content/content', 'reference'); $galleryarray = get_post_gallery_ids($post->ID); ?> <div class="gridbox reference <?php if(DOING_AJAX) {echo " added";} ?>"> <a> <div class="bg_img cursor"<?php if ( $thumbnail_id = get_post_thumbnail_id() ) { if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) ) printf( ' style="background-image: url(%s);"', $image_src[0] ); } ?> onclick="openModal(<?php echo $i; ?>);currentSlide(<?php echo $id ?>)"> </div> <h3><?php the_title(); ?></h3> <p><?php the_time('Y'); ?><br><?php the_category( ', ' ); ?></p> </a> </div> <!-- Modal --> <div id="myModal-<?php echo $i; ?>" class="modal"> <span class="close cursor" onclick="closeModal(<?php echo $i; ?>)">&times;</span> <div class="modal-content"> <?php foreach ($galleryarray as $index => $id) { $image = wp_get_attachment_image_src( $id, ‘thumb’ ); /* $attachment_meta = wp_get_attachment( $id );*/ $number = $index+1; ?> <div id="img-<?php echo $id; ?>" class="mySlides"> <div class="numbertext"><?php echo $number; ?> / <?php echo count($galleryarray); ?></div> <img id="<?php echo $id; ?>" src="<?php echo $image[0]; ?>" style="width:100%"> </div> <?php } ?> <a class="prev" onclick="plusSlides(-1)">&#10094;</a> <a class="next" onclick="plusSlides(1)">&#10095;</a> <div class="caption-container"> <p id="caption"></p> </div> <?php foreach ($galleryarray as $index => $id) { $image = wp_get_attachment_image_src( $id, ‘thumb’ ); /* $attachment_meta = wp_get_attachment( $id );*/ $alt = get_post_meta( $id, '_wp_attachment_image_alt', true); $number = $index+1; ?> <div class="column"> <img id="<?php echo $id; ?>" class="demo cursor" src="<?php echo $image[0]; ?>" style="width:100%" onclick="currentSlide(<?php echo $number ?>)" alt="<?php echo $alt; ?>"> </div> <?php } ?> </div> </div> <?php $i++; endwhile; ?> </div> </div> function openModal(i) { document.getElementById('myModal-'+i).style.display = "block"; document.getElementById('pageHeader').style.zIndex = "0"; document.getElementById('pageFooter').style.zIndex = "0"; document.getElementById('pageContainer').style.textAlign = "left"; } function closeModal(i) { document.getElementById('myModal-'+i).style.display = "none"; document.getElementById('pageHeader').style.zIndex = "10"; document.getElementById('pageFooter').style.zIndex = "9"; document.getElementById('pageContainer').style.textAlign = "center"; } var slideIndex = 1; showSlides(slideIndex); function plusSlides(n) { showSlides(slideIndex += n); } function currentSlide(n) { showSlides(slideIndex = n); } function showSlides(n) { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("demo"); var captionText = document.getElementById("caption"); if (n > slides.length) {slideIndex = 1} if (n < 1) {slideIndex = slides.length;} console.log(slideIndex); for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; captionText.innerHTML = dots[slideIndex-1].alt; } Is it possible to change that code somehow to get it working, or maybe better solution is to sum up every gallery array to one, and make one Modal, where those galleries pop up only when clicking on the right gallery?
  20. Sigmahokies

    table under table

    Hi everyone, I will like to know how to have table under master table. Is it relationship? or how you do that? Thanks, Gary
  21. iwato

    Matomo - PHP Direct (for Dummies)

    NATURE: This is part of a steadfast effort to hack through the thicket of PHP classes and namespaces of which the Matomo application consists. It is not an endeavor for the weak or timid, as the thicket is formidable and the documentation obscure. BACKGROUND: In order to submit a proper report request to the Matomo application the values of certain variables must be known. Although there are generators within the application that have been created to achieve this task, they are not easily accessible, as the thicket is, well, thick. Please find below both the file and code that produces the error message provided. The FILE: <?php /** * Piwik - free/libre analytics platform * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @package Piwik */ use Piwik\ErrorHandler; use Piwik\ExceptionHandler; use Piwik\FrontController; if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { ErrorHandler::registerErrorHandler(); ExceptionHandler::setUp(); } FrontController::setUpSafeMode(); if (!defined('PIWIK_ENABLE_DISPATCH')) { define('PIWIK_ENABLE_DISPATCH', true); } if (PIWIK_ENABLE_DISPATCH) { $environment = new \Piwik\Application\Environment(null); $environment->init(); $controller = FrontController::getInstance(); try { $controller->init(); $response = $controller->dispatch(); if (!is_null($response)) { echo $response; } } catch (Exception $ex) { ExceptionHandler::dieWithHtmlErrorPage($ex); } } The CODE: require_once ('../../../../nudge.online/_utilities/php/matomo/core/dispatch.php'); The ERROR MESSAGE: LINE 16 ErrorHandler::registerErrorHandler(); Now, including the file ErrorHandler.php does not help. Neither does a call to the static function registerErrorHandler() appear to make a difference. Piwik\ErrorHandler::registerErrorHandler(); For the response is always the same Any ideas? Roddy
  22. BACKGROUND: I would like to embed a Matomo widget into a page, but I dare not embed it directly. For, to do so would require that I expose the authorization token that enables knowledgeable visitors of Matomo -- and coding in general -- the ability to view everything about my website that I am able to view. As I, myself, do not yet know what to do with everything that Matomo makes available (it appears endless), I certainly do not want to put it all into the hands of others willy-nilly. It is simply bad business. OBJECTIVE: Read the data into a PHP file, and load the result into the src attribute of an iframe. Below is sample code taken directly from the Matomo website. (The absence of the authorization token assumes that the superuser has given access to all users the right to view whatever they like. I do not wish to grant this privilege). SIMPLE URL https://www.nudge.online/_utilities/php/matomo/index.php?module=Widgetize&action=iframe&widget=1&moduleToWidgetize=Live&actionToWidgetize=getSimpleLastVisitCount&idSite=1&period=day&date=yesterday&disableLink=1&widget=1 EMBEDDING CODE <div id="widgetIframe"><iframe width="100%" height="350" src="https://www.nudge.online/_utilities/php/matomo/index.php?module=Widgetize&action=iframe&widget=1&moduleToWidgetize=Live&actionToWidgetize=getSimpleLastVisitCount&idSite=1&period=day&date=yesterday&disableLink=1&widget=1" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe></div> Obviously, there is no difference in the URLs. QUESTION: If an image can be created by a PHP file and then read into the src attribute of an image tag, surely it must then also be possible to read the HTML content of a PHP file into the src attribute of an iFrame. What is the necessary header argument required? I have tried both " header('Content-Type: text/html'); and header('Content-Type: text/plain'); Neither works! Or, am I just guessing. And, what I am trying to do simply does not work. Roddy
  23. I would like to share with you a message that I posted on the Matomo forum for which I am not expecting a satisfactory reply. I suspect that Matomo will be unwilling to entertain the idea for fear of opening a Pandora's box of insecurity for casual users and thereby endangering its reputation as a secure web utility. Matomo's fear need not be my own, however, with the proper guidance. BACKGROUND: After several weeks of enormous frustration I was finally able to access the Matomo web application directly with PHP. I was able to achieve this somewhat (for me) monumental task by renaming the .htaccess file (see below) in the /matomo/config folder and thus canceling its prohibitive effect. Obviously, this file was placed in the /matomo/config folder as a matter of security -- security, mind you, that I do not wish to compromise. This said, an unending series of HTTP requests uses up an enormous number of resources, and I wish to share the data that I collect about my users with my users via my own custom-built PHP files for which I require direct communication with the Matomo application. (I have no desire to play the governmental game of protect-and-deceive -- read GDPR or NSA). So, I explored the internet and found alternative contents <https://www.slicewise.net/php/piwik-absichern/> to the current .htaccess file in use by Matomo as of 3.5.1. REQUEST: Would anyone like to comment on the merging of these two files (see below) into a workable arrangement that would give me the superuser direct access to the Matomo web-application via PHP, but deny access to everyone else except through those channels already set in place by Matomo for anonymous users and opt-in/out visitors. PROPOSED FILE <Files "*"> AuthUserFile /path/to/piwik.htpasswd AuthName Piwik-Password AuthType Basic <RequireAny> Require valid-user Require ip 127.0.0.1 <your-server-ip> #needed for some scripts </RequireAny> </Files> <Files ~ "^piwik\.(js|php)|robots\.txt|idxsec\.php|favicon\.ico$"> Require all granted </Files> CURRENT FILE <Files "*"> <IfModule mod_version.c> <IfVersion < 2.4> Order Deny,Allow Deny from All </IfVersion> <IfVersion >= 2.4> Require all denied </IfVersion> </IfModule> <IfModule !mod_version.c> <IfModule !mod_authz_core.c> Order Deny,Allow Deny from All </IfModule> <IfModule mod_authz_core.c> Require all denied </IfModule> </IfModule> </Files> My goal is to give my visitors an important glimpse into the reality of data collection and analysis. I now know that I am able to do this my eliminating the .htaccess file. Elimination of the file is, however, not my goal. Roddy
  24. BACKGROUND: I have now tried a number of ways to make two cURL calls within the same Javascript (jQuery) routine. For each new way, I have discovered what I believe to be a reasonable explanation for my failure. For my most recent attempt, however, a good explanation is not forthcoming. To be sure, single AJAX calls with a single cURL call for each yield the desired results. Simply I cannot seem to combine these results simultaneously on the same page. The scenario given below, for example, returns the desired outcome for the second cURL call, but not the first. JAVASCRIPT: $.ajax({ url: '.../VisitsSummary.php', method: 'GET', data: {methodName : '_get', methodName : '_getSumVisitsLengthPretty'}, dataType: 'JSON', statusCode: { 404: function() { alert( "Page not found" ); }}, success: function(visitsSummary_data) { console.log(visitsSummary_data); var tv = visitsSummary_data.nb_visits; var uv = visitsSummary_data.nb_uniq_visitors; var visits_per_unique_visitor = Math.round(tv/uv * 10)/10; $('#so_total_visits').html(visitsSummary_data.nb_visits); $('#so_unique_visitors').html(visitsSummary_data.nb_uniq_visitors); $('#visits_per_visitor').html(visits_per_unique_visitor); $('#so_average_time_spent').html(visitsSummary_data.avg_time_on_site); } }); PHP: if (isset($_GET['methodName'])) { $method_name = $_GET['methodName']; if ($_GET['methodName'] == '_get') { $url = 'https://.../index.php?module=API&action=index&method=VisitsSummary.get&idSite=1&period=year&date=today&format=json&token_auth=&token_auth=...'; $curl_request = curl_init(); curl_setopt($curl_request, CURLOPT_URL, $url); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, false); curl_exec($curl_request); if(curl_errno($curl_request)) { echo 'Curl error: ' . curl_error($curl_request); } curl_close($curl_request); } if ($_GET['methodName'] == '_getSumVisitsLengthPretty') { $url = 'https://.../index.php?module=API&action=index&method=VisitsSummary.getSumVisitsLengthPretty&idSite=1&period=year&date=today&format=json&token_auth=&token_auth=...'; $curl_request = curl_init(); curl_setopt($curl_request, CURLOPT_URL, $url); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, false); curl_exec($curl_request); if(curl_errno($curl_request)) { echo 'Curl error: ' . curl_error($curl_request); } curl_close($curl_request); } } QUESTION: Can you find anything wrong with the above strategy? If so, what would you recommend to replace it? Roddy
  25. I watch more student ask for the PHP code of OTP verification through Email. I think it is very good quary from student. Please help me to make this code as project. and i request W3SCHOOL to post this code in the website. !!!!!! THANK YOU !!!!!
×