August 26, 2013

version update script for a script

Marlboroman213’s Question:

I’m going to try making this easy to understand and hope it makes sense.

I have a PHP script / template and I want the end user to be able to know when I updated something, (eg. template change or a bugfix) and they can click a link to download the updated version from a remote host. I tried the scripts posted on
PHP – How to check a script version and I sorta got this script working:

<?php define('REMOTE_VERSION', http://mysite.com/_client/client_name/update/version_check.txt');
    define('VERSION', '2.0.1');
    $script = file_get_contents(REMOTE_VERSION);
    $version = VERSION;
    if($version == $script) {
        echo "<div class=success> 
    <p>You have the latest version!</p> 
    </div>";
    } else {
        echo "<div class=error> 
    <p>There is a update available!</p> 
    </div>";
    }?>

Well sort of… The .txt file on my remote server just has 2.0.1. Since they are the same version (both 2.0.1), it should read “You have the latest version!” In this case it says “There is a update available!” no matter what number I put in.

define('VERSION', '2.0.1'); //in php above 

2.0.5 //in .txt file on remote server

Says same things as it should because on the remote server is showing a new update (eg. 2.0.5). Can anyone tell me what I am doing wrong?

This might be a typo, but there is an error at your constant definition.

define('REMOTE_VERSION', http://mysite.com/_client/client_name/update/version_check.txt');
                     // ^ Missing quote
March 11, 2013

How To Write A Simple Click Opacity Fade?

Question by user2122160

Okay, so I’m simply trying to make the opacity fade from 0 to 1 and then 1 to 0 on click. I’m assuming that I need to write an if statement. Here is the code as it is right now.

$(document).ready(function() {
     $('#soilink').click(function() {$('#soi').animate({opacity:1}, 400 );}

    );

So right now, if I click on the link on my website, the div area called #soi fades in. However, the second part is that I need to be able to click the link once again so it fades back to 0. Haven’t quite figured that part out.

EDIT

I want this to toggle, however using the toggle function will result in the div completely becoming absent from the html, causing other divs to shift.

Answer by Starx

There is a fadeTo() function for that

$('#soilink').click(function() {
   $('#soi').fadeTo(400, 1);
});

If you are trying create a toggle effect, there is also a fadeToggle() function.

$('#soilink').click(function() {
   $('#soi').fadeToggle(400);
});

Update:

Here is how to do that.

$('#soilink').click(function() {
   $('#soi').stop().fadeTo(400, $('#soi').css('opacity') == 0 ? 1 : 0); 
});
September 2, 2012

how to enable php on a subdomain?

Question by Link

when i’m using the

“www . website . com”

php codes are working but when i’m using it on a subdomain the php script won’t work

“secure . website . com”

how can i enable the use of php code on my subdomain?
i’m using justhost as my server.

my subdomain is located at
/public_html/secure <–folder directory

but when i put the files inside the folder,
php scripts won’t work.
how can i enable php scripts inside my folder?

<?php
phpinfo();
?>

says it’s not supported?

justhost said to contact a php developer regarding this issue that is just what i’m doing.

Answer by Starx

This looks to be because of the server settings.

Contact the support personal at JustHost.com, there are live chat available. You can tell them your issue and fix the server settings.

May 19, 2012

Jquery smooth scroll external anchor link

Question by user1405690

okay can you please help me with a peice of jquery code. Here is what i want to happen. My website is cyberfanatic.com right so. So for example lets just use the footer for now. i have a a tag with the id of footer right. so say if someone visits cyberfanatic.com/#footer right now the page will load and the then jump directly to the bottom of the page to where the anchor link with footer is. How can i get it so that when the page cyberfanatic.com#footer loads that the page loads and the smooth scrolls to the anchor with the id of footer. Please help me out.

Answer by Starx

Use the scrollTo() plugin function

$.scrollTo("#footerid");
March 22, 2012

Get the site status – up or down

Question by john

<?php
$host = 'http://google.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
?>

I’m using the above program to get the status of site. But I always get an offline message.
Is there any mistake with the code?

Answer by stewe

The hostname does not contain http://, that is only the scheme for an URI.

Remove it and try this:

<?php
$host = 'google.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}
?>

Answer by Starx

What about a curl solution?

function checkOnline($domain) {
   $curlInit = curl_init($domain);
   curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
   curl_setopt($curlInit,CURLOPT_HEADER,true);
   curl_setopt($curlInit,CURLOPT_NOBODY,true);
   curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);

   //get answer
   $response = curl_exec($curlInit);

   curl_close($curlInit);
   if ($response) return true;
   return false;
}
if(checkOnline('http://google.com')) { echo "yes"; }
January 9, 2011

Count especific table rows in mysql

Question by NORM

I want to count how many rows I have in a mysql table and display it in html.

For example:

There is: Item 1, Item 2, Item 3, Item 4, Item 5, Item 6

If Item 1 and Item 2 are filled, I want a html code to say – 2 items in row

any ideas?

Answer by Starx

IF its total rows you are after, then as Nishant mentioned above you could do something like this

$query = "SELECT COUNT(*) FROM mytable WHERE myfield='myvalue'"; 

I am counting all the ids, because it will reduce the time taken to calculate the total instead of ‘*’ and

Thanks to Nico, count(*) and count(column) are not so different considering performance. Here is a comparision

Use a where condition to narrow your total as you require.

July 7, 2010

speechbubble tooltip using css and jquery

May 24, 2010

What is the need of JavaScript while developing a page?

Question

I have been developing websites for some time now and I hardly use any Javascript in my pages.

Whatever I can want to do with JavaScript, it is possible through PHP. Just like ajax itself. We can send a regular request instead of a ajax request, can’t we? We can use “include” to include sub part of pages.

So am i missing something about javascript, that I dont know of?

Answer by Starx

If you want your website to be more user friendly and easy to use you will need javascript.

Would you wait till this website (Stackoverflow.com) refresh your page, to see your comment updated?

...

Please fill the form - I will response as fast as I can!