homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

This 46 message thread spans 2 pages: < < 46 ( 1 [2]     
HIding Javascript
can't figure it out
usavetele




msg:1252760
 4:01 pm on Jul 10, 2005 (gmt 0)

Ok, I've found the following for hiding Javascript, but it doesn't work for me. From the coding below, where does the second piece of coding go?

Here's what I found in an old Javascript forum, can't figure it out:

Don't want your javascript copied? Here's a very simple script that will hide it!

On the page where the javascript is placed, add:

<?
session_start();
if(!session_is_registered('allow_script'))
{
session_register('allow_script');
$allow_script = true;
}
?>
<html>
<head>
<script language="javascript" src="script.php"></script>
</head>
<body>
Body goes here...
</body>
</html>

And now create a new file called script.php and place your javascript there:

<?
session_start();
if($allow_script)
{
header("Content-type: text/javascript");
?>

alert("Woohoo! My javascript Works!");

<?
$allow_script = false;
}
?>

 

jd01




msg:1252790
 5:50 am on Jul 22, 2005 (gmt 0)

So, we are at a bit of a stand still. Changing page names once they are probably already indexed in search engines is never a smart thing to do so we can't switch it to php.

If he has access to the .htaccess file (I couldn't tell if he did or not from the previous posts) everything could be switched to the same name php file, and with a little mod_rewrite, the files would not need to change URL's...

RewriteEngine ON
RewriteRule ([^.]+)\.shtml$ /$1.php [L]

Should be all that is necessary to do the trick.

Hope this helps.

Justin

jatar_k




msg:1252791
 4:29 pm on Jul 22, 2005 (gmt 0)

if no SSI is being used then you could also just switch shtml to parse for php and not SSI which would be even easier ;)

usavetele




msg:1252792
 4:46 pm on Jul 22, 2005 (gmt 0)

Hello,

This site I'm making is brand new and am only working on the first page that will need the prices converted. I wanted to make sure to get the first page coded correctly for the currency conversions before making the other product pages with similar price conversions. It would be quite easy at this stage to change the pages to .php is needed. All my files on in this directory: "/public_html" The ".htaccess" file is also located here. Does this help?

Thanks...Laura

[edited by: usavetele at 4:50 pm (utc) on July 22, 2005]

jatar_k




msg:1252793
 4:48 pm on Jul 22, 2005 (gmt 0)

yep

if you can change the extension of that page to php, go for it

then see if it starts working as expected

mcibor




msg:1252794
 9:23 pm on Jul 22, 2005 (gmt 0)

Laura, so you have all the prices stored, eg in database?
Then just use the function I wrote:

<?php
function exchange($price, $xrate) {
return number_format($price * $xrate, 2);
}?>

Set the rates:
<?php
$rate = array(
"USD" => 1.20983,
"YEN" => 0.87635,
"PLN" => 0.45634);
?>

And in the text use the defined function. (It's easier to have one function, for a lot of currencies, than function for each currency):
Our price is <b><?php $price=49.99; echo $price?></b><br>
In America it is <?php echo '$'.exchange($price, $rate["USD"]);?> dollars,<br>
in Japan it is <?php echo 'don\'t know sign for yen'.exchange($price, $rate["YEN"]);?> yens<br>
and in Poland it is <?php echo exchange($price, $rate["PLN"]).'zl';?><br>

Hope this will help you. At first I thougth you're making a currency exchange program, not a shop.
If you change the files to php it should run without any other problems

usavetele




msg:1252795
 5:21 pm on Jul 24, 2005 (gmt 0)

Ok, no laughing but hooly cow, this .php stuff ROCKS! I got the coding jd01 gave me to work great by changing my page extension from .shtml to .php. This program works great. I'm using the following coding jd01 gave me:

<?php
$USexchRate = 1.20379;
$YENexchRate = .78464;
function getUSD($price) {
global $USexchRate; // get the exchange rate we have defined.
$USD = '<b>USD $' . number_format($price * $USexchRate,2) . '</b>';
return $USD;
}
function getYEN($price) {
global $YENexchRate; // get the exchange rate we have defined.
$YEN = '<b>YEN $' . number_format($price * $YENexchRate,2) . '</b>';
return $YEN;
}
?>

<?php include "exchange.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<table> The real price of this item is: $42.99<br>
The USD conversion is: <?php echo getUSD(42.99);?><br>
The YEN conversion is: <?php echo getYEN(42.99);?>
</table>

Thanks for your last post mcibor, but I couldn't get that coding to work. Sorry, I'm a newbie!

So now my currency converter coding orks WONDERFULLY and is hidden, although I suspect it still be found within a few clicks?

The only problem I have now none of my text menues work. They all have the .html extension, so I thought I had to change them to .php as well. I did this to one of my menues, but this didn't work.

What's the trick to get all of my menus "buttons" to work?

Again, thank you so much for the currency converter help. I'm really happen such a forum exists and all of you guys as so willing to help a newbie like me. Words can't describe how happy I am. I've been working on this currency converter problem for almost 2 months now.

Laura

mcibor




msg:1252796
 8:26 pm on Jul 24, 2005 (gmt 0)

Did you change the link in menus to php as well? If yes, then what is the problem - how does it not work?

About my code, sorry I didn't make it simple enough. After two months you'll understand php perfectly, or at least substantially!

About the menus... are they plain html or jacascript? You can post the code here, or create a new topic for that.

See you round
Michal Cibor

jd01




msg:1252797
 9:16 pm on Jul 24, 2005 (gmt 0)

Just wanted to say, Michal's code is better to use than mine.

I code a little different than I think most people do... I write most of my code long hand (inefficient and definitely longer), get everything trouble shot, then comment and shorten it...

The reason I do this is most of the time if I use a compact code to start with I need to fully comment if it is very many lines, and what I have found is I still usually have to go back and shorten and adjust anyway, so one day I just started writing longer individual section of code and using descriptive variables.

I like to be able to just write, so this is the process I normally use:

Round 1: I use descriptive variable names instead of comments and write in a longer 'get it working' form, test and retest, make adjustments, etc.

Round 2: I go back, shorten to more efficient formats. I do not always know what functions I will need or be able to combine when begining, so I write individually, and then combine anything I can to get the least number of functions with the same results for speed. (I also fully comment here.)

Round 3: I do a huge find and replace for my descriptive variable names and generally try to limit to 3 chars or less.

Anyway, I guess when I post, it seems to make more sense to use the readable version for people who are struggling, but that can usually be cut down to a much more efficient version.

Justin

usavetele




msg:1252798
 3:22 am on Jul 25, 2005 (gmt 0)

mcibor,

Yes, I changed my menus to .php and they are set in links like this:

<!--#include virtual="topmenu.php"-->

I'm not sure if this is html or javascript. I know they are server side includes. I did a quick searcho n Googel and see this coding might not be readable to .php, so am I right to assume I'll need to use different coding for php to read them?

Laura

jatar_k




msg:1252799
 5:55 am on Jul 25, 2005 (gmt 0)

ah, that would be SSI and needs the shtml extension but you can do the same thing in php

include [php.net] 'topmenu.php';

g1smd




msg:1252800
 11:11 am on Jul 25, 2005 (gmt 0)

You need to change your "includes" from SSI includes to be PHP includes (slightly different code syntax).

No-one can ever see your PHP source code. It is server-side code. The code is never delivered to the browser - only the result of running the code is.

usavetele




msg:1252801
 3:30 am on Jul 26, 2005 (gmt 0)

HOT DANG! That did the trick and everything is working great!

Thanks so much! I obviously coudlnt' have done it w/o everyone's help!

Laura

jatar_k




msg:1252802
 3:52 am on Jul 26, 2005 (gmt 0)

glad you got it sorted usavetele :)

usavetele




msg:1252803
 3:56 am on Aug 2, 2005 (gmt 0)

Hello,

Me again! I just discovered another problem with converting my pages to .php extensions. I can't get my main/index page to work with the new .php menus/buttons within the page without adding /index.php at the end of my website's main page URL. Hope this makes sense since I can't type my website's URL.

Thanks again for the help.

Laura

jd01




msg:1252804
 6:46 am on Aug 2, 2005 (gmt 0)

Hi Again!

I personally think the best way to handle this is to use mod_rewrite to serve the php page to the .html version, especially for index pages - (I do this with all of my pages, because it makes my php *very* difficult to see or get into...

EG If you try to type in a url with a query string, any information after the? is removed, and you are redirected.

If you type in anyfile.php, you get a forbiden error - wonderful for security, because I don't ever have to worry about someone putting variables in URL's and doing anything ugly - the only variables are passed via theactual/URL.html and they are handled by a pattern match in Apache, before they ever even get to the php checks.)

To handle your index just put this in your .htaccess file:

RewriteEngine ON
RewriteRule ^(index\.html)?$ /index.php [L]

This will give any request for yoursite.com/ or yoursite.com/index.html the information that is on index.php, but the extension will remain .html, so basically the information is moved from the php file to the standard html 'file' that does not really exist.

Hope this helps.

Justin

Added: BTW sorry I typed he in an earlier post instead of she - Just noticed your name is Laura - Good with logic, not reading. Sorry.

usavetele




msg:1252805
 2:31 am on Aug 3, 2005 (gmt 0)

YOU ROCK!

THANK YOUUUUUUUUUUUUUU!

Laura

P.S. No problemo about the "he/she" thing. That's why I thought I'd clarify it with "Laura".

This 46 message thread spans 2 pages: < < 46 ( 1 [2]
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved