tmallen
-
Posts
112 -
Joined
-
Last visited
Never
Posts posted by tmallen
-
-
I set a pretty global variable ($base) that defines the site root. Very useful with my includes. My only problem is using this URL prefix in include() arguments. Example:
<?php $base = '/mybaseurl/'; include($base . 'includes/header.php'); ?>
I've tried smushing $base in there in many different ways, and I ALWAYS get errors. How can I fit $base into this sort of statement?
-
It has everything to do with PHP. The "/" indicating the site root is completely up to PHP. PHP could define "/" to mean anything it wants, and a programmer should be able to control where "/" points...that's the reason for my skepticism.
-
Which is really no better than adding "/clientA" to every absolute root URL and using a site-wide Replace to wipe it out later. I wish there were another way, and it defies reason that PHP doesn't provide a way to set a non-global site root for a specific script or set of scripts.
-
Yes, it does. But imagine:
(1) I have my portfolio website. This is the only one where a URL like "/images/logo.png" would work, because I store this site in the public_html folder, which my server has set as the root.
(2) I have many websites for clients. When I deploy on their server, "/images/logo.png" will work fine for their site, but right now I have it located on my server at "/clientA/images/logo.png". However, for the Header include, I'd like to have <img src="/images/logo.png" />. If I do that, it will point to my website's logo, and not theirs.
(3) I'd like their site root to be located not at public_html/, but at public_html/clientA/ so that I can easily deploy/migrate.
-
Thanks. I took a look. Didn't help though...where should I set this variable? I couldn't even find an example, just code-reference style entries.
-
I'm a freelance web designer and I've begun to use PHP extensively for my clients' websites. A problem I run into is the consistent use of "/" for the site root. My server thinks that that refers to public_html/, meaning I can't test a site with "/" used to recognize the site root if I'm, say, one directory deep. How can I have a specific website recognize its own base folder as the site root? I imagine that in PHP, without touching Apache config files, there's a way to set a new site root, I just don't know how. :(
-
OK. And how do I declare a header that makes $body HTML code? This is over my head.
Note: I'm all for learning, so if you can point me to a relevant link that teaches the specifics of this use of header(Content-type...), that would be just as good.
-
OK, thanks. I feel silly for that one. What about formatting with HTML?
Edit: I tried adding <html> and <body> tags (I closed them too) but that didn't fix things.
-
When I put a newline (\n) into my strings which are later passed onto the $body variable, I actually see the literal "\n" in the email. The same goes for HTML code. Here's my code, note that the indentation looks off but is logical in my document:
<?php # Mail Script v1.0 by {me} $to = 'my email address; $subject = 'Request for more information'; $mailheaders= 'From: Client's name-Website'; // Grab the form and assign to variables $name = $_REQUEST['fName'] .' '. $_REQUEST['lName']; $email = $_REQUEST['email']; $company = $_REQUEST['company']; $address1 = $_REQUEST['address1']; $address2 = $_REQUEST['address2']; $city = $_REQUEST['city']; $state = $_REQUEST['state']; $zip = $_REQUEST['zipCode']; $phone = $_REQUEST['phone']; $about = $_REQUEST['contactAbout']; // Send the mail $body = '<div style="font: 10pt arial; color: #333;">'. '<p>Someone has requested information from the website.</p>'. '<table border="0" cellpadding="3" cellspacing="0" style="font-size: 10pt;">'. '<tr><th align="left">Name:</th> <td> '.$name.' </td></tr>' . '<tr><th align="left">Email:</th> <td> '.$email.' </td></tr>'. '<tr><th align="left">Company:</th> <td> '.$company.' </td></tr>'. '<tr><th align="left">Address:</th> <td> '.$address1.' </td></tr>'. '<tr><th align="left">Address 2:</th> <td> '.$address2.' </td></tr>'. '<tr><th align="left">City:</th> <td> '.$city.' </td></tr>'. '<tr><th align="left">State:</th> <td> '. $state.' </td></tr>'. '<tr><th align="left">Zip:</th> <td> '.$zip.' </td></tr>'. '<tr><th align="left">Phone:</th> <td> '.$phone.' </td></tr>'. '<tr><th align="left">Regarding:</th> <td> '.$about.' </td></tr>'. '</table>'. '</div>'; mail ($to, $subject, $body, $mailheaders); header("Location: ../thanks.php"); ?>
And the results:
<div style="font: 10pt arial; color: #333;"><p>Someone has requested information from the website.</p><table border="0" cellpadding="3" cellspacing="0" style="font-size: 10pt;"><tr><th align="left">Name:</th> <td> my name </td></tr><tr><th align="left">Email:</th> <td> my email </td></tr><tr><th align="left">Company:</th> <td> my company </td></tr><tr><th align="left">Address:</th> <td> </td></tr><tr><th align="left">Address 2:</th> <td> </td></tr><tr><th align="left">City:</th> <td> </td></tr><tr><th align="left">State:</th> <td> Virginia </td></tr><tr><th align="left">Zip:</th> <td> </td></tr><tr><th align="left">Phone:</th> <td> </td></tr><tr><th align="left">Regarding:</th> <td> </td></tr></table></div>Why is this? What am I doing wrong here?
Include a scalar in my include argument?
in PHP Coding Help
Posted
Thanks for the help guys. I'm manually setting my own root because I'm building locally and then migrating a couple times. Using a $base URL lets me easily adapt my site to different environments.