Solved

embed php in javascript

Posted on 2008-06-18
13
780 Views
Last Modified: 2012-06-21
I have the following piece of code that I need to run on a server that does not support php so I have been advised to convert the entire code in javascript with document.write and have them as javascript functions. I am not sure how exactly it needs to be done as I am not very experienced in JS. Any kind of help will be sincerely appreciated. The code is as under




code.txt
0
Comment
Question by:sulentho
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 168 total points
ID: 21818168
sulentho,

You can't convert that to Javascript.  That script does server side operations like connect to a database, etc.  Client side script like Javascript can't do it.  Find out if your new server supports a different server language and convert the PHP to that server language (e.g. ASP, .NET, etc).  Javascript won't work at all.

Let me know if you have any questions or need more information.

b0lsc0tt

p.s.  That advise is shocking to say the least.  Javascript is never a great substitute for PHP or a server language.  In most cases, like this, it can't replace the server script.  If the advise came from someone that didn't even ask what the code does or look at it then I would be very cautious about other advise on PHP, Javascript, etc.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21818179
sulentho,

By the way ... please don't take the PS note personal and it isn't meant to be a general statement on the person giving the advise.  Maybe there was some miscommunication.  Otherwise they just don't know PHP and Javascript.  Just a heads up. :)

b0lsc0tt
0
 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 166 total points
ID: 21818282
As b0lsc0tt says, converting that code to Javascript is impossible.  But if you have a server, surely it supports some server-side scripting if not PHP - if it's IIS for example, you can write the code in ASP.  Without server-side scripting, your code won't work - it is as simple as that.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21818288
Sorry, I didn't read your post completely it seems, b0lsc0tt... I have actually just repeated everything you said!!  Don't mind me, it's getting late...
0
 

Author Comment

by:sulentho
ID: 21819079
Thank you very much for the advice guys, I will find out further if the server has any kind of scripting language like ASP on it to help. Thanks so much for the help and have a great day
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 166 total points
ID: 21820169
Alternatively look into the costs of a php-enabled server. Depending on your situation it can be anything from shared-hosted $50 a year, to dedicated at hundred dollars a year.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21823279
sulentho,
Your welcome!  Let us know if we can help more with this or you have a question about what you learn from your new host.  If you have a lot of PHP scripts and your new host will just not support them or your old DB then you might really consider what Roonaan suggested.  There are lots of hosting providers that offer PHP.

purplepomegranite,
No worries!  Thanks for noticing and the apology.  Get some rest so you will be very helpful when Sulentho needs more help.  Yesterday was like that for me too.  ;)

bol
0
 

Author Comment

by:sulentho
ID: 21827689
I need to echo the following lines of code in javscript which will in turn document.write the html . I am not sure about the string escape characters so will need your help on this. Any help on this will be appreciated. Thanks and have a great day


<a href="http://www.insidetoday.com/ban_click.php?id=<?=$hed_ban['banner_id']?>&url=<?=$hed_ban['link_url']?>" target="_blank"><? if($hed_ban['banner_image']){ ?><img src="http://www.insidetoday.com/bannerimages/<?=$hed_ban['banner_image']?>" alt="ad" width="468" height="60" border="0" /><? } ?></a>
 
this is what I have started with
header("Content-type: text/javascript");
echo "document.write('<a href="http://www.insidetoday.com/ban_click.php?id=<?=$hed_ban['banner_id']?>&url=<?=$hed_ban['link_url']?>" target="_blank"><? if($hed_ban['banner_image']){ ?><img src="http://www.insidetoday.com/bannerimages/<?=$hed_ban['banner_image']?>" alt="ad" width="468" height="60" border="0" />);";

Open in new window

0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21827714
Hate to say, but this is another question, which means you should start it as a new question and assign points accordingly.  As far as I can see, it isn't even related to the original question except for the fact it mentions JavaScript...
0
 

Author Comment

by:sulentho
ID: 21827743
Thank you purplepomegranite will do so accordingly.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21828949
Feel free to post the URL of the new question in a comment here if you'd like our help on it too.  If you need anymore help or have a question about this question then let us know.

bol
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question