
-Karl-
Members-
Posts
421 -
Joined
-
Last visited
Everything posted by -Karl-
-
Hello, I'm trying to find a way to use jQuery to change a div to either display:none; or display:block; So far the toggle function works fine, here's my code: <script type="text/javascript"> $(document).ready(function() { $("#login").click(function(e) { $('.login-form').toggle(); }); $("#register").click(function(e) { $('.register-form').toggle(); }); $(document).mouseup(function(e) { $('.register-form').hide(); }); }); </script> As you can see, the #login just toggles between show and hide. Whereas register, simply shows when it's clicked once, but if it's clicked again it doesn't hide like the login. However, I need the mouseup on both so that it also hides if a visitor clicks off the div completely. What's a work around for this?
-
After a bit of messing around with your advice, got it down to this: $hours = floor($seen/60); $minutes = $seen-($hours*60); $days = floor(($seen/60)/24); $hours = floor($seen/60)-($days*24); $last_seen = ''; if($days > 0) { $last_seen .= "$days day".($days==1?'':'s'); } if($hours > 0) { $last_seen .= " $hours hour".($hours==1?'':'s'); } $last_seen .= " $minutes minute".($minutes==1?'':'s'); Thanks a lot.
-
Yeah the $more is irrelevant. Like I said though, it works perfectly, so everything is in the right place. Removed a bit of pointless stuff after having a second look through the code if($seen > 60) { $hours = floor($seen/60); $minutes = $seen-($hours*60); $days = floor(($seen/60)/24); $hours = floor($seen/60)-($days*24); if($minutes == 1) { $minute = ' minute '; } else { $minute = ' minutes '; } if($hours == 1) { $hour = ' hour '; } else { $hour = ' hours '; } if($days == 1) { $day = ' day '; } else { $day = ' days '; } if($days > 0) { $seen = $days . $day . $hours . $hour . $minutes . $minute . 'ago'; } else { $seen = $hours . $hour . $minutes . $minute . 'ago'; } } else { if($seen == 1) { $minute = ' minute '; } else { $minute = ' minutes '; } $seen = $seen . $minute . 'ago'; } Basically, it's the defining whether it's an hour, or multiple hours, which makes the code look so long.
-
Hello, I'm trying to create a staff online widget which shows when they were last active. Here's what I have so far, it works perfectly fine but I'm just wondering if there's a much simpler way of doing it, if so, how? $seen = floor((time("now")-$row['time'])/60); $more = false; if($seen > 60) { $more = true; $hours = floor($seen/60); $minutes = $seen-($hours*60); if(($seen > 24) && ($more == true)) { $days = floor(($seen/60)/24); $hours = floor($seen/60)-($days*24); } if($minutes == 1) { $minute = ' minute '; } else { $minute = ' minutes '; } if($hours == 1) { $hour = ' hour '; } else { $hour = ' hours '; } if($days == 1) { $day = ' day '; } else { $day = ' days '; } if($days > 0) { $seen = $days . $day . $hours . $hour . $minutes . $minute . 'ago'; } else { $seen = $hours . $hour . $minutes . $minute . 'ago'; } } else { if($seen == 1) { $minute = ' minute '; } else { $minute = ' minutes '; } $seen = $seen . $minute . 'ago'; }
-
Yes it's correct. And sorry, I just always use PHP tags. I managed to fix it by using exec('sudo csf -x 2>&1',$disable); Now the script is all working fine, it blocks connections from port 80, etc, but people are still able to connect via certain ports when they shouldn't be able to (as stated in the csf.conf file). But I guess that's a csf issue not a PHP issue. Thanks for all your help anyway.
-
Fixed those issues, now I have: Array ( [0] => Can't locate Crypt/CBC.pm in @INC (@INC contains: /etc/csf /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/sbin/csf line 10. [1] => BEGIN failed--compilation aborted at /usr/sbin/csf line 10. ) Array ( ) Array ( ) Blocked Not a clue how to fix that.
-
Already answered the above questions: exec('csf -x 2>&1',$disable); exec('chmod 777 /etc/csf/ 2>&1',$chmod); exec('yes | cp block.conf /etc/csf/csf.conf 2>&1',$block); exec('csf -s 2>&1'); print_r($disable); print_r($chmod); print_r($block); echo 'Blocked'; Returned: Array ( [0] => sh: /usr/sbin/csf: Permission denied ) Array ( [0] => chmod: changing permissions of `/etc/csf/': Operation not permitted ) Is there a possible workaround for this?
-
Stopping the service did indeed stop it from being CHMOD'd automatically. The only issue being, would I be able to do exec('csf -x'); to stop it, then chmod the directory via the PHP script as long as the chown is set to the apache user? Or would csf -x not work since it will be apache trying to run it, not root?
-
So I've been messing around a little. I can copy the file to /var/www, /var, /, and even /etc/ But once I try to copy to /etc/csf, I get the permission error! The current permissions for /etc/csf are: drw------- 10 root root 4096 Sep 2 02:10 csf However, if I do chmod 777 /etc/csf/ it will change, but if I do ls -la again it will have changed. Any ideas?
-
Won't make a difference if I don't have the correct permissions... It will make a difference if your current path is not four levels below the root of the server. The absolute path to /etc is not going to change. I would just use an absolute path there. The's nothing wrong with the levels, I also tried it with an absolute path, same error.
-
I assume the first since the file isn't copied.
-
Already tried that without any look. Also, I echo'd whoami(); and the username was apache, I chown'd the directory and the file to apache, chmod'd 777 as well, still no luck.
-
Won't make a difference if I don't have the correct permissions...
-
Okay, I've added "2>&1" on to the end of the first command now. And I've received an error! Finally. cp: accessing `../../../etc/csf/csf.conf': Permission denied Now, the problem is, how can I give permission in order to access it? Also, I just ran "echo get_current_user();" and it echo'd "root". When root clearly has permissions to access that location. Any ideas?
-
Hello, I'm having an issue with exec(), I've also tried shell_exec() too. Basically, I have a server in which I need to run a PHP script, via HTTP, to run a command via the terminal. This is not for any malicious use. What I'm trying to do is to copy a file and overwrite another one via the PHP script, and then to restart a service with it too. The service is CSF. exec('yes | cp block.conf ../../../etc/csf/csf.conf',$block); shell_exec('csf -r'); print_r($block); echo 'Blocked'; Basically, that's should copy block.conf in to the csf.conf file and then restart csf, which will block certain ports. There's also another file called unblock.conf, which will do the opposite of the above. Any ideas what could be causing the issues? I've CHMODed the file to 777, etc. Nothing is echo'd apart from "Blocked" but that doesn't give me any indication why it's not working correctly and the $block array is empty.
-
Sorry should have updated this really. I fixed it myself.
-
Hello, I'm using jQuery tabs and Ajax to send post data to an included page, but the data isn't being sent/received and I can't figure out why. Here's my jQuery. $(function() { var postData = {}; $( ".tabs" ).tabs({ select: function(event, ui) { $('#r').html('<div style="padding: 5px;"><img src="<?php echo BASE_URL.'themes/'.$theme.'/images/ajax-loader.png'; ?>" /></div>'); postData = { uid: parseInt($(ui.tab).data('uid')) }; }, ajaxOptions: { type: 'POST', data: postData, error: function( xhr, status, index, anchor ) { $( anchor.hash ).html( "<div style='padding: 5px;'>Content could not be loaded, sorry about that.</div>" ); } } }); $(".tabs ul li > a").attr('title', ''); }); And here's the tabs. <div class="tabs"> <ul> <li><a href="file1.php" data-uid="<?php echo $_GET['id']; ?>" title="r">File 1</a></li> <li><a href="file2.php" title="r" data-uid="<?php echo $_GET['id']; ?>">File 2</a></li> <li><a href="file3.php" title="r" data-uid="<?php echo $_GET['id']; ?>">File 3</a></li> </ul> <div id="r"></div> </div> In file1.php I have a print_r($_POST); But all that's shown is Array( ). Does anyone have any ideas?
-
Hello, So I have a problem and I cannot think of a way around it. Basically, I use jQuery tabs and Ajax to load a file and include it. However, I don't want a user to be able to directly access the file which is included. Example: <ul> <li><a href="file1.php?id=<?php echo $_GET['id']; ?>">Link 1</a></li> <li><a href="file2.php">Link 2</a></li> </ul> Let's called the main page index.php, so when a user goes to index.php they have tabs, Link 1 and Link 2, when they click Link 1, file.php is included in to a pre-defined div through Ajax. I want the script to still be able to access the file, but I don't want visitors to be able to access it directly. So I came up with this cunning idea: index.php session_start(); $_SESSION['IS_INCLUDED'] = true; file1.php session_start(); if($_SESSION['IS_INCLUDED'] == true) { echo 'Do stuff!'; unset($_SESSION['IS_INCLUDED']); } else { echo 'You cannot access this file directly.'; } This works perfecty, but not as required. The problem is there is more than one tab, if they click Link 1, it works fine, if they click Link 2, it works fine because the SESSION isn't yet added, however, if they click back on to Link 1, they get the error. This happens because the SESSION is unset, but without it being unset anyone could access the file directly if they've visited the page once. Does anyone have any idea how I can get around this problem?
-
You just need the full URL to the file then you can do: $url = '/public_html/images/image1.png'; unlink($url); http://www.php.net/manual/en/function.unlink.php Also, just so you know, you must have the correct CHMOD permissions in order to do this.
-
What's the best way to display a star rating, which includes half values. At the moment I have: $value = 3.66; $value = round(($value*2), 0)/2; switch($value) { case 0: echo 0 stars; break; case 0.5: echo half a star; break; } What's a more efficient way to do this?
-
The query is fine: SELECT id,username FROM `users` Fixed now, I changed $query->fetchAll(PDO::FETCH_ASSOC) to $query->fetch(PDO::FETCH_ASSOC). Thanks!
-
Still no luck, here is what I have at the moment: public function selectIt($table, $rows = '*', $where = null, $order = null) { $q = 'SELECT '.$rows.' FROM `'.$table.'`'; if($where != null) $q .= ' WHERE '.$where; if($order != null) $q .= ' ORDER BY '.$order; $query = $this->db->prepare($q); $query->execute(); $row = $query->fetchAll(PDO::FETCH_ASSOC); $hi = count($row); $arr = array(); $query->execute(); while ($row = $query->fetchAll(PDO::FETCH_ASSOC)) { foreach ($row as $k => $v) { $arr[$k][] = $v; } } echo '<pre>'; print_r($arr); echo '</pre>'; } Which returns this: Array ( [0] => Array ( [0] => Array ( [id] => 1 [username] => karl ) ) [1] => Array ( [0] => Array ( [id] => 2 [username] => admin ) ) )
-
Basically, I've been trying to create an array dynamically from a mysql database. I have a query where I select the id and username from the table, but I want to dynamically build an array from it. Right now my array is: Array ( [0] => Array ( [id] => 1 [username] => karl ) [1] => Array ( [id] => 2 [username] => admin ) ) However, I'm having difficulty trying to get it to look like this: Array ( [id] => Array ( [1] => 1 [2] => 2 ) [username] => Array ( [1] => karl [2] => admin ) ) So that I can just call $row['id'][$i]; to display both id's in a table, or whatever. The only problem is, I need the rows from the mysql database to dynamically construct the array. So say I select id, username, password, the above array will create another part: [password] => Array ( [1] => passforkarl [2] => passforadmin ) I'm not sure if that makes an sense at all, but I just can't get my mind around it.
-
I have some PHP code which grabs data from an outside source, depending on a name which is grabbed from the database. However, when you run the script it takes a long time to load because of the amount of times it needs to grab data. What would be the best way to run each part, one at a time, echo it, then run the next one, echo it. On the same page. If you get what I mean?