Forum Moderators: coopster
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;
}
?>
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
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]
<?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>
<?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
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
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
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
include [php.net] 'topmenu.php';
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
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.