Dr Design - Javascript to PHP

The waiting room is full! Join the queue — and the Good Dr. Design will see you next time! But for now, he’s rolling up his sleeves and lending a hand to today’s patients…

Dream Rollovers

Hi!
Can you tell me why all the rollovers that I make in Dreamweaver don’t work in Mac Explorer v.5? Is there any way to make them work? Thank you very, very much…
Amando from Mexico City.

Amando, I haven’t looked at Dreamweaver’s rollover Javascript. Sometimes simpler is better. I’m quite fond of Andy Mathews (Gravity Digital) simple rollover Javascript, which he posted some time ago on the SitePoint Forums. Perhaps you’ll have more luck with this one.

<script language="javascript">  <!-- 

// Pre-load images  if (document.images) {    image1on = new Image();    image1on.src = "images/about_us_on.gif";    image1off = new Image();    image1off.src = "images/about_us_off.gif";  } 

function changeImages() {    if (document.images) {      for (var i=0; i<changeImages.arguments.length; i+=2) {        document[changeImages.arguments[i]].src =         eval(changeImages.arguments[i+1] + ".src");      }    }  } 

// -->  </script>

Here’s an example of its use in HTML:

<a href="about_us.shtml" onmouseover="changeImages('image1',   'image1on')" onmouseout="changeImages('image1', 'image1off')">  <img name="image1" src="images/about_us_off.gif" border=0></a>

Tracking the Relatives

Hey Doc,
I’ve designed and set up a small Website exclusively for family pictures. I’m using the Apache server software on a home PC.

My question is: how can I track the people that come to the site? I have set up a login name and password, which should restrict access… however, as word of mouth gets around in the family I’m sure that I’ll get lots of hits from distant relatives, and given that I’m a curious person I would like to know who does log in.

I’ve set up one login name and password so I can’t distinguish the users in this way… I have also, through HTML code, set up a screen to ask for a name and then place a cookie on the user’s PC, so that they know how often they’ve been to the site (and eventually, can see if there are any updates on the site).
Gary

Gary, I know where you’re coming from. There’s nothing more fun than keeping up with the family gossip and finding out what the relatives are up to. I’d probably opt for a bit of server side scripting in PHP or ASP for this one. However, you may not be using any server-side scripting, so let’s see if we can hatch an ingenious plan to perform visitor monitoring from the client-side using Javascript!

The technique I’ll use assumes you have a Web log analysis tool, or you’re true geek and read over your log files. Check out this list of available log analysis tools. Popular packages that run on Linux servers include Webalizer, Analog and AWStats. You’ll also find log analysis programs that will run under Windows.

Now, for the fun…

The technique is a little "edgy". Known as "clear gif spyware" or a "Web beacon", some people resent that online advertisers use this technique to track visitors. But that’s exactly what we want to achieve. If you were running a commercial Website and used this method it would be advisable (and in tune with online privacy ethics) to disclose in your privacy policy that you track visitors using cookies.

A "Web beacon" uses Javascript to append a query string onto the address of a clear (transparent 1×1 pixel) gif, which is loaded into the Web page. The query string will be ignored by the Web server when it serves up the clear gif, except that the HTTP GET request will be logged in your Website access logs. When you analyse your logs, you’ll be able to trace your visitors through the requests for the clear gif. For example, you will have entries such as:

[10/Oct/2002:03:16:42 +0000] "GET /clear.gif?name=Mary HTTP/1.1"

Here’s the code for a page that tracks any "cookied" visitor through the function setGif(), and will also set a cookie with the user’s name wn they submit the form that asks them for their name.

<html>  <head>  <script language = "javascript"> 

// set the cookie expiry date to be in twelve months  expireDate = new Date;  expireDate.setMonth(expireDate.getMonth() + 12); 

// convert the expiry date to GMT format  cookieDate = expireDate.toGMTString(); 

// declare userName as global  var userName = ""; 

// setCookie() sets a cookie with the userName  // submitted by the form userForm  function setCookie() {    userName = document.userForm.name.value;      cookieString = "userName=" + userName + "; expires=" +     cookieDate + ";";    document.cookie = cookieString;    alert('Welcome ' + userName + '!'); 

// call function setGif() so that we track this visitor's page view    // now that we know their name!    setGif();    return false;  } 

// setGif() will embed the clear gif into the document  // and append the cookied userName so that we can track  // the user in our website access log.  function setGif() {    if(document.cookie != "") {      userName = document.cookie.split("=")[1];      imageTag = '<img src="clear.gif?name=' + userName + '" width=1       height=1>';      document.write(imageTag);    }  } 

</script>  </head> 

<body>  <form name = "userForm">  Select a username:  <input type=text name="name" onBlur="return setCookie()">  <input type="submit" value="submit" onClick="return setCookie()">  </form> 

<script language="javascript">    setGif();  </script>  </body>  </html>

Variable Assignment Blues

Hello Doctor,
I have a quick question for you. I am new to PHP programming and have quickly found myself stuck. After connecting to a MySQL database through PHP, I am using the following PHP code to insert rows into an existing table…

// If an artist has been submitted,
// add them to the database.
if ($addArtist == "Add") {
$sql = "INSERT INTO Artists SET
Name='$AddName',
bio='$AddBio';";
if (@mysql_query($sql)) {
echo("Artist Added");
} else {
echo("<p>Error adding submitted order: " .
mysql_error() . "</p>");

}
}

However, I need to also add rows into a different table under the same database at the same time. I have had no success with adding it this way (only one sql statement is recognized, not both)…

    // If an artist has been submitted,       // add it them the database.       if ($addArtist == "Add") {         $sql = "INSERT INTO Artists SET         Name='$AddName',         bio='$AddBio'";         $sql = "INSERT INTO Pictures SET         fileSRC='$AddPicture'";         if (@mysql_query($sql)) {           echo("Artist Added");         } else {           echo("<p>Error adding submitted order: " .                mysql_error() . "</p>");         }       } I've looked everywhere and have not found a solution.  Please let me know if you can help. Thank you, David
 David, it always makes my heart rejoice to hear of someone finding the path to open source enlightenment and wisdom. You will be a master of PHP in no time!   Here is the problem with your second code example. When you assign your second query string to the variable $sql, this will "overwrite" the previous value of the variable, which is the first query string you assigned. Here's an example:
$myString = "foo";   $myString = "bar";   echo $myString;
 This will output: bar However, if I write: $myString = "foo";   echo $myString;   echo '<br>';   $myString = "bar";   echo $myString; This will output: foo   bar Back in your code, you might want to try something like this:
if ($addArtist == "Add") {  

// first insert the record into Artists      $sql = "INSERT INTO Artists SET           Name='$AddName',           bio='$AddBio'";  

if (@mysql_query($sql)) {         echo("Artist Added");      } else {         echo("<p>Error adding submitted order: " .               mysql_error() . "</p>");      }  

// next insert the record to Pictures      $sql = "INSERT INTO Pictures SET          fileSRC='$AddPicture'";  

if (@mysql_query($sql)) {         echo("Picture Added");      } else {         echo("<p>Error adding submitted order: " .                mysql_error() . "</p>");      }         }
 That should do it!  
  Targeting A Frame Doctor, In a frameset, I’ve created a link to a page that should load in another frame. The link comes from "frame3" and the linked page should appear in "frame2" — but it doesn’t!!!!!!

No matter what I put into the "target" attribute the page still appears in "frame3" thus removing my navigation-bar. I have tried _top, _parent, default, _blank etc. in the "TARGET" field. Nothing seems to work. Help!!! Renà RenÃ, I’m sensing some frustration from your use of exclamation marks. Sometimes, as desperate as I might be to finish off some coding, when I feel like bashing my head against the monitor, I know it’s time to ease off the caffeine and go outside, rediscover what sunlight is, and charge up on Vitamin D. If you want to target a frame from another frame you need to use the target frame’s name. Let’s say we have the following frameset:
<frameset rows="50%,*">      <frame name="frame1" src="navigation.html">      <frame name="frame2" src="body.html">    </frameset>
 And navigation.html (which is loaded into frame1) has the following link which will open up in frame2:
<a href="somepage.html" target="frame2">click here     to open the page inside frame2.</a>
 Viola! Lights, Camera, Action! Doc, I designed some really snazzy rollover/navigation buttons for my Website in Swish and exported them as .swf (flash) files. I just can’t get my HTML editor (Homesite 4.5) to call them out :( I thought: 


<a href "main.html">img src"img/main.swf" width="200"     height="32" alt"" border="0"></a><br>
 would do it, but no luck. Now I’m back to boring old .jpgs  Thanks for any advice,  Ryan Aye-ah! That anchor tag is very mangled. Remember a tag always takes this form:
<tagType attribute=value attribute2=value2 attribute3=value3>
 Values that are strings must be enclosed in quotes. For example:
<img src="myImage.jgp" width=100 height=100 border=0 alt="Just an image">

 Anyway, that doesn’t really get us any closer to solving the problem. I am happy to admit I’m out of my league on this one. You might want to look into adding actions to your Swish movies. Here’s a tutorial that looks promising — good luck! And don’t forget to ask in the SitePoint Forums if you need quick advice from some pretty handy Swish users. Including Headers and Footers Dr. Design, How can I include a header and footer in an html page? Thanks, Winston Most Web servers support Server Side Includes (SSI). To be able to use SSI in an html page you need to use the file extension .shtml on your Web pages, so that the Web server knows to parse the file and process the include directives. Here is an example of using SSI to include a header and footer from different files:
<!--#include file="header.html" -->    <p>Some regular old HTML goes here.</p>    <!--#include file="footer.html" -->
 Don’t forget to save the page with the .shtml extension! You can also use SSI include directives in your ASP files. Which reminds me, I saw patient in the clinic two months back with a similar case of the includes. You can read the advice I gave then — hope it helps. Consulting hours are over, but make sure your questions get answered when the surgery opens again next month!

Replay

Category: other Time: 2002-10-12 Views: 3
Tags:

Related post

  • Shall I need to use MD5 algorithm in both JavaScript and PHP for login authentication? 2012-07-26

    I have a login form with username and password. I post this form data to a PHP file. For security reasons I want to encrypt my password in the database and network. Now I have done now following steps. Get username, password from user and using HTTP

  • How to display drawings from ArcGIS on Google Maps using JavaScript or PHP? 2014-03-15

    my client has ArcGIS installed on his PC and he has designed roads, hospitals, houses, and parks of a specific area in ArcGIS he needs his system online. challenging task for me is how can I get all drawing information from his ArcGIS that I can show

  • Crouching Javascript, Hidden PHP [1] 2004-08-30

    Jason has been pondering the options of getting Javascript talking to PHP or, put another way, how to get a web page to load data without reloading (or at least without appearing to reload). Why do this? Because you can give the impression of a rich

  • Pass Javascript Array - PHP 2011-02-17

    Let's say I have a javascript array with a bunch of elements (anywhere from 50-200). I want to send that to PHP (prepared statement) using ajax. Currently, I .load a php file many times inside of a loop, but I want to convert that into an array and s

  • Are UML class diagrams adequate to design javascript systems? 2012-09-15

    Given that UML is oriented towards a more classic approach to object orientation, is it still usable in a reliable way to design javascript systems? One specific problem that I can see is that class diagrams are, in fact, a structural view of the sys

  • Best way for beginner to learn JavaScript and PHP coding 2013-08-21

    I have a job interview coming up and in job description it states I need to be able to write JavaScript and PHP coding. Now its been a while since I did JavaScript and PHP coding. I am planning to use w3schools to be able to start of with the basics.

  • Any way to use WGS84 latlng to dynamically get state plane EPSG code? Either javascript or PHP 2013-12-06

    I am developing an online project that needs to be able to accept a WGS84 lat lng anywhere in the lower 48 states and produce the corresponding state plane coordinates. Once I know the state plane EPSG code then I can use http://spatialreference.org

  • Book Review: Practical Design Patterns in PHP 2014-10-18

    This review of Brandon Savage's Practical Design Patterns in PHP will include my own opinions and impressions about both the book, and the aspect of self-publishing. Many thanks to Brandon for giving me a review copy. Design patterns are about common

  • Login Tokens Remote DataServer for use in a Javascript/HTML-PHP environment 2015-01-22

    I've asked this question on stackoverflow, but i think this is a more appropriate place for it. I'm creating an app for iOS, Android and the Web. I created a separate Restful Data Service that is meant to be consumed by all three environments, so I s

  • Polyglot array_extend() function for Javascript and PHP 2015-02-06

    This is a polyglot function I've made out of fun. The goal is to grab n arrays (or Javascript Objects) and 'extend' them in order to obtain a single array with all the values. This function runs both in Javascript and PHP. Please, try to ignore some

  • Polyglot function to sum all the numbers in an array in Javascript and PHP 2015-03-31

    This, again, is a very simple code. This is my 2nd polyglot question and this time I've tried to do something that I miss sometimes in Javascript. PHP has the array_sum() function, but Javascript has no direct equivalent. So, I decided to make one th

  • JavaScript and PHP Libraries Used by WordPress 2015-05-26

    Almost all modern software (including platforms such as WordPress) rely on third party libraries. That's because, as developers, we don't need to reinvent the wheel. If I had to develop software that uses HTTP abstraction, I might use a package like

  • Passing data from Javascript to php with Laravel 5.1 2016-01-23

    I need to pass data from Javascript to php using Laravel 5.1 So right now I have a blank page with input(name='q'). When I start typing it sends the query via Ajax data:{q: query} to php so in php I am taking the value from q $query = e(Input::get('q

  • Android Base64 decode different from javascript and PhP 2016-01-30

    Sorry for asking this question twice times, but I did research 2 hours... I have problem with Base64 decode String in my Android. For example: encoded string: VgFzJ1+TrFa7WsXS5w== The results in javascript and PHP: Vs'_¬V»ZÅÒç The result in my Androi

  • disable firebug extension through javascript or php 2016-02-12

    i want to disable firebug extension icon in popup window.can we hide or remove it in popup window through javascript or php? i searched here and found this code but its not working. if (! ('console' in window) || !('firebug' in console)) { var names

  • adding row using javascript in php and html5 2016-02-13

    see the picture .I want to repeat the same field when i click on the add button. I am new to javascript and php. I tried the code for adding row using javascript, but its not working. Can any one help me to write the code. <form action="act_master

  • Crouching Javascript, Hidden PHP [2] 2004-08-31

    Continuing yesterday's rant, this installment should (hopefully) get a bit more juicy, if I can work out where it's going. First up, already some good feedback to the last part (thanks!), most to-the-point being Alan; I can tell you having worked wit

  • MVC - Control Class - Architecture / Design - Structure Review - PHP 2012-06-18

    The client side version in JavaScript is here This is the server side version of my control module. How does the structure look. PostScript Because this is a small prototype/app I have preferences or things I will consider when I will have a working

  • Should JavaScript and PHP objects be treated as different objects in an interaction diagram? 2014-01-13

    I'm drawing a communication diagram for an application where you can buy books. I'm using domain-driven design and have a 'shop' object, a 'cart' object, and a 'book' object. My first communication diagram, for when the user first comes to the site,

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.821 (s). 13 q(s)