PHP on iWeb '08

Discussion in 'Web Design and Development' started by JelvisChan, Jan 11, 2009.

  1. JelvisChan macrumors member

    Joined:
    Jan 9, 2009
    #1
    IWeb / PHP Help!!​


    Does anyone know a way to use php on iWeb '08?

    Here are the codes I am trying to process:

    HTML:
    HTML:
    
    <form method="post" action="contact.php">
    Email: <input name="email" type="text"><br>
    Message:<br>
    <textarea name="message" rows="15" cols="40"></textarea><br>
    <input type="submit">
    </form>
    -and-

    PHP:
    PHP:
    <?php
    $to 
    "you@yoursite.com";
    $subject "Join Us";
    $email $_REQUEST['email'] ;
    $message $_REQUEST['message'] ;
    $headers "From: $email";
    $sent mail($to$subject$message$headers) ;
    if(
    $sent)
    {print 
    "Your mail was sent successfully"; }
    else
    {print 
    "We encountered an error sending your mail"; }
    ?>

    How, on iWeb, is there a way so that I can put the HTML inside a snippet, and when you click submit query, it redirects to the thank you, good job, or whatever page? This would be EXTREMELY helpful!

    Help if you can! Thanks.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    You would add the form as a HTML Snippet. Then the PHP would be its own page, and wouldn't look like your other iWeb pages. Also, PHP isn't on MobileMe so you'll be able to do this if your site is hosted on a server that has PHP support.

    Also, if you figure things out, you should really look at pre-built contact forms. In its current for, the PHP you have their will easily be taken over by a spammer and turn your web site into spam host essentially. This can lead to your web site being pulled off the internet because it becomes a nuisance to businesses. What your script lacks is sanitizing the text being sent from the form. There are some tutorials that will teach you how to properly check input for malicious intent, but people have already created nice scripts for doing all this, so I recommend doing some searches for some.
     
  3. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #3

    Okay, this is what I have done in relation to your help:

    I have put the html code into a snippet and then I put the PHP code into my computer's suer's sites folder -- which I turned on php for.

    I named it sendmail.php.

    On the html snippet, this action says: http://Jelvis/~jelvischan1/sendmail.php . <-- jelvischan1 is my computer's username

    I tried the form on my dad's and sister's computer, and they both say that the link cannot be found.

    I double-checked both URLs. Can other machines see my personal website on Web Sharing ( System Preferences )?

    Is there a way to do this? If so, can you tell me the steps?
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    If they other computers are hooked to your network then they'll access your computer through your IP address. Some thing along the lines of http://198.162.1.101/~jelvischan1/ and that should take them to your home page. Also make sure you have web sharing turned on in System Preferences. That's also where it should tell you the IP address to connect through.
     
  5. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #5
    Is there a way to make that website universal so that I can use the action part of the html form to link to that and process the form other than only the people on my local network being able to process the form?
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    You'll need to configure your home router to forward port 80 to your machine's IP address. Then other people will enter the IP address of your router to access your site. This also means any time your router's IP address changes (anywhere between a day or a few months) people will have to enter the new IP to see your site. There are some services like DynDNS that help remedy this to an extent, but otherwise you would want to get a web host so you don't have to make such modifications and you could also get a domain name so they don't have to enter the IP address.
     
  7. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    Depends on your router. See it's manual.
     
  9. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #9
    Is there an easier way to do this because I am only 13.

    I really just want to make my /users/sites folder universal without too much preparation.

    Can't I just add them somewhere so that they just put a URL into the address bar and it loads, or is that too complicated?

    I just need it so that when you click "Submit" on a form, it redirects you to a thank you page and the data sent is to my email address. I know how to do that -- the codes and scripts, but I don't know how to make it so that anybody can submit it, not just someone in my local network.

    I tried putting the php script into my iWeb folders at me.com, but this is not a PHP enabled server, that is what Web Sharing is for, but only for my local network. Making this universal is what I need to do, but may need some work to be done.

    Easy way to do this?
    Fill Free to Share your ideas anyone!
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    I already told you the easy way. It's something that takes maybe a minute to do. I can't tell you how to configure your router though because I don't know what kind you have or how it's currently setup. Otherwise, have your parents buy you some web space. There are some free options for hosting as well if you search around, but a domain name will cost money.
     
  11. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #11
    I have plenty of web space on iWeb -- about 5.0 GB
    I can buy a domain name, but will that automatically go to my users/sites pages if people type the new domain in?

    If so, what is the best/cheapest place to buy a domain name? Yahoo?
    If there is a free way to do this, that would be better because I really don't have a lot of money, and, if I am correct, I have to pay by the month.
     
  12. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #12
    Well, iWeb doesn't have that much space, MobileMe does. You can generally buy a domain name for under $10 a year (paid a year at a time), pretty cheap. Just search around for the best deal and be sure to read the fine print. The free alternative would be the DynDNS that I mentioned before. With just the domain name you'll have to point it at your router IP address, which changes from time-to-time (and thus you'l have to watch out for when it changes so you can manually change the IP address fot the domain name), but with DynDNS it knows when the IP changes and makes the adjustments for you.
     
  13. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #13
    I made an account on DynDNS, and I put my ip address into the host page.
    Once you type the IP in and save, the link will take you to the pages at /Macintosh HD/Library/Webserver/Documents, right?

    Also, is the link now universal?
    How do I link it to my Users/Sites folder rather than to the Webserver/Documents?
     
  14. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #14
    First, the internet doesn't discriminate based on age. Whether you're 13 or 103, setting up a web site takes the same effort. Second, your age isn't an excuse. I know lots of kids who are as much of a tech nerd, or even more so, than me. :)

    Edit: ok, wow, you figured it out while I was typing that great huge post.

    The link is now "universal" yes. To get it to your Users/Sites folder, you type in the full link, e.g.

    http://jelvischan.dyndns.org/~jelvis/

    Or you could insert a quick HTTP redirect in the Webserver/Documents folder.
     
  15. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #15
    Some people's brains aren't able to take in all of the web scripting/processing like older people do because of experience.


    I just took online tutorials about a year ago on HTML and Javascript, so sorry if I bothered you.

    I tested the link on my machine, please test it on yours to see if you get the default index.html link on your mac. Here is the link:

    http://lost.webhop.net/~jelvischan1

    I am going to change it later because I think it is a gay URL :)

    Hope it works, and thanks for all the help everyone!!
     
  16. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #16
    No bother. And my post wasn't meant to be condescending. I spent over half an hour typing up a long post about the basics of hosting and DynDNS and when I submitted the post, you had already figured all of that out. I don't think you're giving yourself enough credit.

    I tried the link you provided on my PC at work, and it didn't load, but I will try again on my Mac at home.
     
  17. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #17
    It didn't load for me either. Were you able to forward port 80 on your router to your computer? That step is still required if not.
     
  18. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #18
    No, I am still not sure how to do that.

    All I did was go to that website - DynDLS -- and made an account and then put in the host link with my computer's IP Address.

    I click save changes and I tested the link : http://lost.webhop.net/~jelvischan1

    It works for me and my dad's machine, but this could be only for my local network.

    I am really perplexed when it comes to forward port 80, and I really don't want to mess with the internet modem. Is that the only way?!? I was soooo close.
     
  19. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #19
    Yes it is definitely a required step, ans as I have said the steps to do it depend on the router itself. Can you look at it and find out the make and model? Most have manuals online, so we may be able to help if we know what type it is. Also be sure to get this information from the router, not the cable modem, unless they are one in the same. I think some companies have them together now.

    The steps are generally speaking,
    1. Go to URL 198.162.1.0 (or some variant)
    2. Click on networking / forwarding page
    3. Specify your IP
    4. Specify port number
    5. Save and apply
    6. Restart router
     
  20. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #20
    Yes, this is the only way to get web traffic onto your computer from outside your home network.

    What's happening is that your DynDNS account is set up correctly, so when I access your DynDNS weblink (lost.webhop.net), the DynDNS server gives me the IP address which your router is using to connect to the internet. So we're knocking on your door, in a virtual sense, and awaiting an answer...

    But your router is also a firewall, and by default it is set to ignore all incoming requests. So our browsers sit, requesting, and hear nothing back. Your browser, and your dad's browser, work because the router is smart enough to see that they're both already inside the firewall.

    By forwarding port 80 you are telling your router "it's ok, I'm expecting people to send incoming web requests, because I'm running a web server on one of my computers, and here is where you should send those requests to. Please continue to block everything else, but allow web requests to come in."

    It's like telling everyone your address to come visit you, but the security guard at the door is refusing to answer the door when people knock. You have to tell the guard that you're expecting certain people, and when they knock, please escort them to the right room in your house.

    The only other way to do this is to buy a web hosting package, one that lets you run PHP scripts, and run everything off one of their servers. (99% of web hosts provide PHP -- unfortunately iWeb/MobileMe falls into the 1% that don't). You upload your script to their server, link to their server, and let them take care of it. This way nobody even has to know anything about where your computer lives on the 'net. Of course, this does cost money, all the way from "free" (usually with catches, like ads) to between $3-30 per month. Personally I'm a fan of DreamHost.
     
  21. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #21
    An analogy

    I'll complete this analogy to complete the picture for anyone reading this thread who might find it useful.

    Running a web server on one of my computers is like setting up a lemonade stand in my room. People inside my house know that they can go to "Jay's Room" and buy lemonade, and life is good.

    But now I want people from my neighborhood to be able to buy lemonade too. I can't put up a poster that says "lemonade - come to Jay's room", because nobody outside my house knows what that is. I can, however, put up a poster that says "lemonade - come to 123 Main Street". Let's say I also register a company name, Super Lemonade, and put a listing in the phone book that directs anyone searching for "Super Lemonade" to "123 Main Street".

    (This is the equivalent of registering a domain name and pointing it to a specific IP address, or registering on DynDNS to do the same thing. Note that if I move away from "123 Main Street" I must update my phone book listing for "Super Lemonade" to point to my new address.)

    So now people see the Super Lemonade listing, come to 123 Main Street, and knock on the front door. But they're not getting any answer, because the security guard doesn't recognize them and refuses to let them in. (This is your home router firewall, doing its job.)

    The final step is, I have to tell my security guard that if people ask for Super Lemonade, they can be escorted to Jay's Room. Keep locking everyone else out.

    The other option, of course, is to rent a storefront at the mall, and run Super Lemonade out of the storefront. They'll provide all the security and janitorial services and I don't have to worry about any risk to my home, but of course I have to pay for that.

    ... now I'm thirsty. :D
     
  22. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #22
    I have asked my dad if the Port 80 is on, and he said that it has to be on to be able to communicate with the web and the people on it.

    PHP is already on Mac OS X, it is just not enabled by default.
    I have done all the steps to enable PHP on my Mac, but it is just allowing people to access my Users/Sites folder on the web.

    My firewall should allow all incoming connections outside my network because Port 80 is turned on.

    If there is something wrong or something wrong about what I am doing, please tell me pronto because I have been working on this for a while and shutting off now is really not what I want to do right now because making my personal PHP enabled site universal is the last step to completing my process.

    I am so close to finishing that it is not even funny.:confused::confused::confused::confused:
     
  23. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #23
    With respect, this is not correct.

    I can prove it with this simple thought experiment. Suppose you have five different computers in your home network. Suppose they are all running OS X, all with web sharing turned on, all running PHP, all listening on port 80, and each machine is set up to run a DIFFERENT script when you visit the page.

    Now you click on http://lost.webhop.net/~jelvischan1. Which computer will receive the connection? Which script will run?

    The answer is: the one you set up your router to connect with. You MUST configure your router to forward incoming port 80 TCP traffic to ONE of your computers in order to resolve this dilemma.

    The fact that your computers can connect to the internet has nothing to do with inbound TCP port 80. In fact if you were to run a packet sniffer and analyze the incoming/outgoing traffic, you'll find that connections are being created with all kinds of port numbers. They are created as needed, and closed again when they're done.

    You must follow some sort of procedure, like the following, which is a link to instructions for a typical Linksys router.

    http://www.dnsexit.com/support/knowledge_base/router/Linksys-2.htm

    If you, or someone else, has not explicitly followed those above steps, and specifically entered the local IP address of YOUR computer, then the router has no way to know that you intend for all incoming HTTP traffic to come to YOUR computer running the PHP script, as opposed to, say, your sister's computer.

    Nothing wrong with taking a break from it for a while. :) Best of luck, anyway, I hope our advice has been helpful.
     
  24. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #24
    Do you know the way to enable it with T-Online.de?

    I live in Germany, so everything on the router website is in German.
     
  25. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #25
    I found one router that T-Online possibly uses, the Teledat 400 (PDF). The guide is in English and German. Eve if this isn't your specific router it may have enough information for you to get into a little more. On page 16 is starts talking about the web interface for it. It has you go to 192.168.1.1 and the default password is 1234. If the password has been changed I can't really help, except that a hard reset will some times reset all that (usually involves sticking a paper clip in a small hole for a couple seconds). Apparently the interface is in German though. The guide doesn't talk about port forwarding though. It's possible it doesn't have that feature.

    If you can pick off any other primary names on the device, even if it is in German it may help us track it down. I don't speak German, but Google does pretty well translating pages.
     

Share This Page