QuickOldCar
Staff Alumni-
Posts
2,972 -
Joined
-
Last visited
-
Days Won
28
Everything posted by QuickOldCar
-
Hard to help when don't see any code for it or a hint of whats wrong. Enable WP_DEBUG in wp-config.php https://codex.wordpress.org/WP_DEBUG
-
Are you looking to echo the name? You say want 100 results but the if statement would only show for admin or joe. foreach($my_results as $user_data){ if($user_data -> user_login === 'admin' || $user_data -> user_login === 'joe'){ echo "Admin<br />"; }else{ echo $user_data->name."<br />"; } }
-
Surely that is not your entire plugin. Did you check out the wordpress codex about plugins? If you really wanted to create your own plugin for this the wp queries get complex and a few joins on the tables. Here is just an example of a plugin that will show only if is admin or network superadmin <?php /* Plugin Name: I Am Admin Plugin URI: http://site.com Description: Shows a message are admin Author: admin@site.com Version: 1.0 Author URI: http://site.com */ function i_am_admin(){ if(current_user_can('manage_options') || is_super_admin()) { echo " <style type='text/css'> #admin_panel { top: auto !important; bottom: 0; } p.admin_panel { top: -20; width: 100%; background-color:white; color: red; border-style:solid; border-width:1px; text-decoration:none; text-shadow:1px 1px 0px #000000; text-align:center; margin-top:40px; margin-bottom:0px; margin-right: auto; margin-left: auto; padding-top: 20px; padding:0px; } </STYLE>"; echo "<div><p class='admin_panel'>I am The Admin</p></div>"; } } add_action('wp_head', 'i_am_admin'); ?> As for the search queries you can download a search plugin and examine what they used.(or use theirs and wrap it with the check for admin) https://wordpress.org/plugins/wp-user-listing-and-searching/
-
I thought the same thing Barand, don't see the OP exploding the data. Each appears to have a single value.
-
If the levels are a single value do it in one loop and make arrays comparing the levels $adminusers = array(); $superusers = array(); $sql = "SELECT (username,level) FROM permissions WHERE level = 'Admin' OR level = 'Super User' "; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_assoc($result)){ if($row['level'] == 'Admin'){ $adminusers[] = $row['username']; }else{ $superusers[] = $row['username']; } } Or if wanted to get all users privileges $adminusers = array(); $superusers = array(); $users = array(); $sql = "SELECT (username,level) FROM permissions"; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_assoc($result)){ if($row['level'] == 'Admin'){ $adminusers[] = $row['username']; }elseif($row['level'] == 'Super User'){ $superusers[] = $row['username']; }else{ $users[] = $row['username']; } } Now this would be ok if wanted a huge list, I personally like to just check what their level is on login. Set in a session if matches admin or superuser. Otherwise no login or not matching those in session would be set as a normal user in session. On the subject of naming levels it's easier to do a numbering one such as 1-10.
-
It's hard to track unique clicks unless are logged in registered users your website. Only other way to track is by the remote ip and is not reliable, ip's change for many users. Setting a session or cookie and checking that as well can help not get duplicate ip clicks or views. If wanted to do such a thing I would use a different table just for those, ip and url, ip being unique, then do a count how many for that url. To get the ip: $ip = $_SERVER['REMOTE_ADDR']; if (strstr($ip, ', ')) { $ips = explode(', ', $ip); $ip = $ips[0]; } You can pass the banner url as a GET parameter for tracking total views or clicking, it's the same idea. For every time is clicked or viewed you do a +1 Here is a way I have used to track api's, is another that I simply use datetime but for this I wanted to return results easier per year,month or day and keep them as uniques. The other method was running a script hourly and fetching the count from text files. sql CREATE TABLE IF NOT EXISTS `track` ( `id` int(11) NOT NULL AUTO_INCREMENT, `url` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `t_year` int(4) NOT NULL, `t_month` int(2) NOT NULL, `t_day` int(2) NOT NULL, `views` bigint(20) NOT NULL DEFAULT '0', `clicks` bigint(20) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `unique_index` (`url`,`t_year`,`t_month`,`t_day`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=8 ; sql dummy data INSERT INTO `track` (`id`, `url`, `t_year`, `t_month`, `t_day`, `views`, `clicks`) VALUES (1, 'site.com', 2014, 2, 8, 2467, 55), (2, 'site2.com', 2015, 5, 23, 1482, 12), (3, 'site3.com', 2015, 1, 5, 2, 0), (4, 'site3.com', 2015, 5, 5, 1, 0), (5, 'site6.com', 2015, 5, 22, 3, 0), (6, 'site6.com', 2015, 5, 23, 2, 7), (7, 'site.com', 2015, 5, 23, 1, 0); So for either clicks or views you use the same script track.php?set=clicks&url=banner-url.com track.php?set=views&url=banner-url.com track.php <?php date_default_timezone_set('America/New_York'); if (isset($_GET['url']) && trim($_GET['url']) != '') { $url = trim($_GET['url']); } if (isset($_GET['set']) && (trim($_GET['set']) == 'views' || trim($_GET['set']) == 'clicks')) { $views_or_clicks = trim($_GET['set']); } if (isset($url) && isset($views_or_clicks)) { $dbhostname = 'localhost'; $dbusername = 'user'; $dbpassword = 'password'; $dbdatabasename = 'table'; $con = mysqli_connect($dbhostname, $dbusername, $dbpassword, $dbdatabasename) or die("Error connecting to database"); $url = mysqli_real_escape_string($con, $url); $date = time(); $t_year = date("Y", $date); $t_month = date("m", $date); $t_day = date("d", $date); $sql = "INSERT INTO track (url,t_year,t_month,t_day,{$views_or_clicks}) VALUES ('{$url}','{$t_year}','{$t_month}','{$t_day}','1') ON DUPLICATE KEY UPDATE {$views_or_clicks}={$views_or_clicks}+1"; mysqli_query($con, $sql); } ?> You can pull any data want like sum of all views for a specific url just for the day, a certain month or year, get as crazy as want with it. A few select queries: //one url, views just year $sql = "SELECT url, SUM(views) AS totals from track WHERE url='{$url}' AND t_year='{$t_year}'"; //one url, views year and month $sql = "SELECT url, SUM(views) AS totals from track WHERE url='{$url}' AND t_year='{$t_year}' AND t_month='{$t_month}'"; //one url, views year,month and day $sql = "SELECT url, SUM(views) AS totals from track WHERE url='{$url}' AND t_year='{$t_year}' AND t_month='{$t_month}' AND t_day='{$t_day}'"; //one url, total views $sql = "SELECT url, SUM(views) AS totals from track WHERE url='{$url}'"; //all urls total views $sql = "SELECT url, SUM(views) AS totals FROM track GROUP BY url"; //all urls total clicks $sql = "SELECT url, SUM(clicks) AS totals FROM track GROUP BY url"; $result = mysqli_query($con, $sql); while($row = mysqli_fetch_assoc($result)){ echo $row['url']." - ".$row['totals']."<br />"; }
-
I'm not sure how much knowledge you have of php or coding in general, here is the php manual and tutorial. This could all be done. Using html forms with POST or GET requests. There is various ways to handle the storage such as a database, session, or even flat files. The editing or deletion process can be done using forms or requests, more dynamic methods without refreshing the current page done with javascript/ajax or jquery. I'll try to explain and link to some specific areas of interest. For the database use either pdo or mysqli functions for handling the connections,insert,update or fetch. user accounts with login password_hash() and password_verify() should be the 2 functions using to add users passwords and verify is them You would save the username,hashed password and any other information into a database upon registration. For login you would query the database that user and using password_verify to ensure the password is correct. Once you verify the user/password you create a session $_SESSION['username'] = $user; You can save a specific session key and value for that user, some use a numbering system for admin or user privileges and additionally their username session_start(); must be at the top of every script for this to work $_SESSION is an array of the session keys and values $_POST or $_GET methods from the html form are arrays, so you would check if one of your desired array keys is set and not empty to determine what to do. isset() checks if a variable is set trim() would remove any whitespace from the ends some examples session_start(); if(isset($_SESSION['username']) && trim($_SESSION['username']) !=''){ $username = trim($_SESSION['username']); $logged_in = true; }else{ $username = ''; $logged_in = false; } if(isset($_POST['key']) && trim($_POST['key']) !=''){ $value = trim($_POST['key']); }else{ $value = ''; } You should always use filters and escape the input to ensure is data you expect, clean and safe. ctype character type checking validate filter sanitize filter If using pdo use prepared statements, if using mysqli functions use mysqli_real_escape_string() For redirecting a user a different location such as they don't have high enough privileges use header() Take one step at a time and any specific questions you have during creation post again and include the related code you have. What you want is basically your own cms and not some simple code.
-
The part you do not show in code is where the $date variable comes from or what it's value could be. Going by your code the $date value should be a timestamp. If tried this would work. date_default_timezone_set('America/New_York');//set server timezone $month = ""; $date = time(); //timestamp $tmp = date("F",$date);//formatted date from timestamp showing full month if($tmp !== $month){ $month = $tmp; echo $month."<br />"; }else{ echo "Was the month $month<br />"; } If your date is already a formatted date then would want to use strtotime() on it. date_default_timezone_set('America/New_York');//set server timezone $month = ""; $date = date('Y-m-d h:i:s A');//string formatted date $tmp = date("F",strtotime($date));//converted the string formatted date to timestamp if($tmp !== $month){ $month = $tmp; echo $month."<br />"; }else{ echo "Was the month $month<br />"; }
-
If you use mysql_fetch_array() or mysql_fetch_assoc() would get the array of multiple results. Then you could loop these results in a while statement. The way your code is now is only finding out how many rows exist. $num_rowe = mysql_num_rows($chkcomms); mysql_* functions have been deprecated and should consider using PDO or mysqli_* functions.
-
I'll explain it as simple as can. Make a folder named feed and create an index.php file within or create a new php file anywhere you desire. first line would be header info to declare it's document type header("Content-Type: application/rss+xml; charset=UTF-8"); connect to your database perform a select query to database use LIMIT to return limited amount of results if there is a result larger than zero continue Adding the rss format code $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>'; $rssfeed .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'; $rssfeed .= '<channel>'; $rssfeed .= '<atom:link href="http://site.com/feed/" rel="self" type="application/rss+xml"/>'; $rssfeed .= '<title>Site.com latest feeds</title>'; $rssfeed .= '<link>http://site.com</link>'; $rssfeed .= '<description>This is the description of my site</description>'; $rssfeed .= '<language>en-us</language>'; $rssfeed .= "<copyright>Copyright (C) 2009-" .date('Y'). " Site.com</copyright>"; Now do a while loop on your results code within the loop $rssfeed .= "<item>"; $rssfeed .= "<title>" . $row['title'] . "</title>"; $rssfeed .= "<guid>" . $row['permalink'] . "</guid>"; $rssfeed .= "<description><![CDATA[ <p>". $row['description'] ."</p> ]]></description>"; $rssfeed .= "<link>" . $row['permalink'] ."</link>"; $rssfeed .= "<pubDate>" . $row['date'] . "</pubDate>"; $rssfeed .= "</item>"; end of while loop closing tags and echo out $rssfeed $rssfeed .= "</channel>"; $rssfeed .= "</rss>"; echo $rssfeed;
-
You can post any work you need done in the freelancer section called Job Offerings
-
For normal users I show them data from the database, if have permission to edit then full or live editor code is shown using whatever content filters would like to use. http://ckeditor.com/demo#acf
-
It's a lot easier to get a firm grasp on procedural coding first and then work your way up to OOP if that's what you desire. OOP is a different way of thinking with objects, methods and properties versus just procedures.(where everything can become an object) The class is basically the blueprint of the object and a way to store methods/functions and properties/values Methods are functions and part of the object Properties are values of the class and part of the object I think the key to understanding php coding is to learn what it can do, the functions, manipulating and sorting data such as arrays and values. It's a lot simpler and faster to write procedural coding than to construct something in OOP, it would overcomplicate it. For those coming from a strict language have to take into account php is a loose language and almost a free-for-all, a little imagination and can do some very interesting things with php. So here is the php manual and the tutorial, lots of information around the net is outdated, wrong or bad practices. If have a question or get stuck the people here are glad to answer them.
-
A website owner can use the api's from other sites and then add a script their own sites to detect if logged in or not. What that api reveals about a user could vary. Website owner would apply and get an app id. For facebook they have a login app. https://developers.facebook.com/products/login/ And in more detail https://developers.facebook.com/products/login/ Now what's interesting here is just intended to detect if a person logged in or not and give them a login button. There is additionally the api for doing logins another site which sends a token,email and users id. FB.api('/me', function(response) { console.log(JSON.stringify(response)); }); Which returns { "id":"101540562372987329832845483", "email":"example@example.com", "first_name":"Bob", [ ... ] } I would guess that facebook has some security to not let anyone know your id unless you use that site to log in and they happen to use either a facebook login button or some custom one of theirs that is really facebook, Not to mention if you used same login credentials as facebook account. I should hope facebook has some same domain policies for iframes. Anything is possible but it shouldn't be possible to me unless you actually logged in through their system, not merely visiting.
-
New to PHP - getting a simple form to work
QuickOldCar replied to stjonesMSI's topic in PHP Coding Help
Barand posted to the mail section there. -
Is a lot of invalid html, go here and check it out. https://validator.w3.org/check?uri=http%3A%2F%2Fwww.kbduct.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0 Since links work when click another link other than home I examined the html. On the home page is this. </div> <div class="mainarea"> <a href="http://awfsfair.org/" style=" display: block; width: 181px; height: 100px; "> <div id="eBanner" style=" position: absolute; right: 269px; top: 141px; z-index: 9999; height: 100px; width: 185px; "> </a> </div> <div class="wrapper"> Working pages elsewhere. </div> <div class="mainarea"> <div class="wrapper"> Seems like that banner and z-index causing the issue
-
which is the best stack-engine out there ?
QuickOldCar replied to dil_bert's topic in Other Web Server Software
Is a pile of pre-made question and answer scripts out there, most will see are commercial licenses. There are some clone scripts for stackexchange,yahoo answers and whatnot, some free and others cost money. What one is the best? The one that does what you want and works. You are basically just looking for any cms that can do users accounts, posts with categories and tags, comments that can be ranked. You can even transform forums, wordpress or joomla into something like this. Is probably even plugins made for it. -
array_combine() or array_merge() , depends what you need to do.
-
This doesn't have to do with the code itself but the logic behind it. Doesn't matter if the round values higher than eight are similar? I was just wondering why add only eight highest.
-
You should check out the php manual and the tutorial Here is a simple example can try. <?php //read a file $my_file = "filename.txt"; if (file_exists($my_file)) { $data = file($my_file); $total = count($data); echo "<br />Total lines: $total<br />"; foreach ($data as $line) { $line = trim($line); echo "$line<br />"; } //add a new line,note the a $write = fopen($my_file, 'a+'); //rewind($write);//append to top $message = "added a new line here\r\n"; fputs($write, $message); fclose($write); /* //note the w, this will overwrite the entire contents $write = fopen($my_file, 'w'); $message = "I just added this line and overwrote the file\r\n"; fputs($write, $message); fclose($write); */ } else { echo "No file to display"; } ?>
-
You can use css to change the color of a button or link depending their events. .button:hover { background: #008000; } a:visited { background: #ffffff; } You can also use javascript and functions with onclick,mouseover,etc... http://lmgtfy.com/?q=javascript+button+change+color Post whatever related code you have, otherwise is just guessing.
-
Forget the ajax part of it for now until get the basics working. Store the dates in the database with datetime formatted as YYYY-MM-DD HH:MM:SS The today date would be the current date, then you modify the current date with +24 or -24 hours using strtotime() A query would look something like this. $query = "SELECT * FROM table_name BETWEEN ('".$from."' AND '".$to."')"; or $query = "SELECT * FROM table_name WHERE date >= '$from' AND date <= '$to'"; I would use a default date as today within index.php if no parameters set in the url, otherwise use what is specified. This is just one of many ways possible. I wrote up one using as you described just yesterday,today and tomorrow but I felt using dates as the parameter was a better way so can do any date. index.php?date=2015-5-15 no date parameter defaults to the current date <?php date_default_timezone_set("America/New_York"); if (isset($_GET['date']) && trim($_GET['date']) != '') { $date = trim($_GET['date']); } else { $date = date('Y-m-d'); } if (($timestamp = strtotime($date)) === false) { $date = date('Y-m-d'); } $query = "SELECT * FROM table_name WHERE `timestamp` BETWEEN ('".$date."' AND '".$date."')"; $current = date('Y-m-d'); $previous = date('Y-m-d', strtotime("$date - 24 HOURS")); $next = date('Y-m-d', strtotime("$date + 24 HOURS")); echo "<a href='?date=$current'>Today</a> "; echo "<a href='?date=$previous'>Previous</a> "; echo "<a href='?date=$next'>Next</a><br />"; echo $query; ?> Results: SELECT * FROM table_name WHERE `timestamp` BETWEEN ('2015-05-15' AND '2015-05-15')
-
A little coding help please if(strpos($b
QuickOldCar replied to nighttraindb's topic in PHP Coding Help
Since you say the issue seems to be it not adding the text file into it's folder... try adding some checking to your code echo out a message each step to see what actions it's doing make sure directory exists is_dir() What about folder permissions? is_writable() will check if the directory exists and also is writable file_exists() or is_file() to check it actually got there