Php question

Show off new creations, get help, or just chat about all aspects of web development and design.

Php question

Postby Dr Evil on Sun Nov 25, 2012 8:36 pm

hey Guys,

I'm creating an email form, and Im struggling with the code at the end, what am I missing?

Code: Select all
   if
      ($captcha == "yes"}
       mail{$mailto, $mail_subject,$mail_body, $headers);
   if
      ($captcha == "yes"}
      echo '<META HTTP:-EQUIV=Refresh CONTENT="0; URL='http://www.domain.com'">';      
User avatar
Dr Evil
1337 p0st3r
1337 p0st3r
 
Joined: Sun Dec 12, 2010 7:22 pm
Location: Youngstown, Ohio

Re: Php question

Postby LordDz on Sun Nov 25, 2012 11:05 pm

I know nothing of php, but why do you have a } instead of a ) for the if statement?
User avatar
LordDz
May Contain Skills
May Contain Skills
 
Joined: Mon Sep 01, 2008 12:28 pm
Location: Hammer Crash Logs

Re: Php question

Postby zombie@computer on Sun Nov 25, 2012 11:06 pm

also theres a { at the mail function and single quotes breaking up the echo'ed string.

You, my friend, need syntax highlighting. FAST.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Php question

Postby Dr Evil on Sun Nov 25, 2012 11:07 pm

yah I caught that...

but I still cant get the page to redirect after the user hits the submit button

heres the entire code to get a better idea of what im trying to do

Code: Select all
<?php
// Make sure to go through the HTML form //
   if
      ($_SERVER["REQUEST_METHOD"] <> "POST")
   die
      ("Unauthorized Access is not allowed.");
      
// Set the CAPTCHA Variables: //
   if
      {S_POST["capycha"] != $_SESSION["pass"]) $captcha = "no";
   if
      {S_POST["capycha"] != $_SESSION["pass"]) $captcha = "yes";

// E-Mail Header Information //
   $headers = 'MIME-Verson: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $headers .= 'From: ' .$_POST['cust_email_addr']. "\r\n";
   $headers .= 'Reply-To: ' .$_POST['cust_email_addr']. "\r\n";
   $mail_to = "sales@suprtech.com";
   $mail_subject = "Service Order Request";
   
// E-Mail Body Information //
   // Cusstomer Information //
   $mail_boddy .= "\n <b>Customer Information" '\n';
   $mail_boddy .= "\n <br><b>- Customer Name:</b>: " .$_POST['cust_name']. "\n";
   $mail_boddy .= "\n <br><b>- Company Name:</b>: " .$_POST['cust_co_name']. "\n";
   $mail_boddy .= "\n <br><b>- Address:</b>: " .$_POST['cust_address']. "\n";
   $mail_boddy .= "\n <br><b>- City:</b>: " .$_POST['cust_city']. "\n";
   $mail_boddy .= "\n <br><b>- Province/State:</b>: " .$_POST['cust_state']. "\n";
   $mail_boddy .= "\n <br><b>- Postal/Zip Code:</b>: " .$_POST['cust_postal']. "\n";
   $mail_boddy .= "\n <br><b>- Customer Email:</b>: " .$_POST['cust_email_addr']. "\n";
   $mail_boddy .= "\n <br><b>- Customer Phone:</b>: " .$_POST['cust_phone']. "\n";
   
   // Customer Account Information //
   $mail_boddy .= "\n <b>Customer Account Information" '\n';
   $mail_boddy .= "\n <br><b>- Requested Package Type:</b>: " .$_POST['cust_package']. "\n";
   $mail_boddy .= "\n <br><b>- Requested Domain:</b>: " .$_POST['cust_domain']. "\n";
   $mail_boddy .= "\n <br><b>- Requested Password:</b>: " .$_POST['cust_passwd']. "\n";
   $mail_boddy .= "\n <br><b>- Requested Password Confirmation:</b>: " .$_POST['cust_domain']. "\n";
   
// Action for correct or incorrect CAPTCHA code //
   if ($captcha == "no") {
               echo '<script type="text/javascript">';
               echo 'alert("Wrong Validation Code.");';
               echo 'window.setTimeout(window.history.back().0); ';
               echo '</script>'
               }
// Actions to perform after the "Submit" button is pressed //
   if
      ($captcha == "yes")
       mail{$mailto, $mail_subject,$mail_body, $headers);
   if
      ($captcha == "yes"}
      echo '<META HTTP:-EQUIV=Refresh CONTENT="0; URL='http://www.paypal.com'">';         
               
               
User avatar
Dr Evil
1337 p0st3r
1337 p0st3r
 
Joined: Sun Dec 12, 2010 7:22 pm
Location: Youngstown, Ohio

Re: Php question

Postby skoften on Sun Nov 25, 2012 11:08 pm

Missing some context here. The only problem I see atm is that one of your if is incorrect.

Code: Select all
      if($captcha == "yes") {
           mail{$mailto, $mail_subject,$mail_body, $headers);
      }
      if($captcha == "yes") {
          echo '<META HTTP:-EQUIV=Refresh CONTENT="0; URL='http://www.domain.com'">';
      }


Also, the variable captcha is of type string? you should make it a boolean so you can do if($captcha) { } or if($!captcha){ bla }. No reason for it to be a string im guessing.

Edit: damn you guys
User avatar
skoften
May Contain Skills
May Contain Skills
 
Joined: Thu Apr 09, 2009 3:30 pm
Location: Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´

Re: Php question

Postby skoften on Sun Nov 25, 2012 11:18 pm

I dont know shit about PHP but this worked on my php server:

Code: Select all
header("Location: https://paypal.com/");

instead of
Code: Select all
echo '<META HTTP:-EQUIV=Refresh CONTENT="0; URL='http://www.domain.com'">';


Might not work since the page/headers are already provided upon coming to this part of the code. (????)

Always redirect to https instead of http with stuff like paypal.
User avatar
skoften
May Contain Skills
May Contain Skills
 
Joined: Thu Apr 09, 2009 3:30 pm
Location: Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´Ôåg¾´

Re: Php question

Postby zombie@computer on Mon Nov 26, 2012 7:16 pm

Dr Evil wrote:yah I caught that...

but I still cant get the page to redirect after the user hits the submit button

heres the entire code to get a better idea of what im trying to do

Code: Select all
<?php
// Make sure to go through the HTML form //
   if
      ($_SERVER["REQUEST_METHOD"] <> "POST")
   die
      ("Unauthorized Access is not allowed.");
      
// Set the CAPTCHA Variables: //
   if
      {S_POST["capycha"] != $_SESSION["pass"]) $captcha = "no";
   if
      {S_POST["capycha"] != $_SESSION["pass"]) $captcha = "yes";

// E-Mail Header Information //
   $headers = 'MIME-Verson: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $headers .= 'From: ' .$_POST['cust_email_addr']. "\r\n";
   $headers .= 'Reply-To: ' .$_POST['cust_email_addr']. "\r\n";
   $mail_to = "sales@suprtech.com";
   $mail_subject = "Service Order Request";
   
// E-Mail Body Information //
   // Cusstomer Information //
   $mail_boddy .= "\n <b>Customer Information" '\n';
   $mail_boddy .= "\n <br><b>- Customer Name:</b>: " .$_POST['cust_name']. "\n";
   $mail_boddy .= "\n <br><b>- Company Name:</b>: " .$_POST['cust_co_name']. "\n";
   $mail_boddy .= "\n <br><b>- Address:</b>: " .$_POST['cust_address']. "\n";
   $mail_boddy .= "\n <br><b>- City:</b>: " .$_POST['cust_city']. "\n";
   $mail_boddy .= "\n <br><b>- Province/State:</b>: " .$_POST['cust_state']. "\n";
   $mail_boddy .= "\n <br><b>- Postal/Zip Code:</b>: " .$_POST['cust_postal']. "\n";
   $mail_boddy .= "\n <br><b>- Customer Email:</b>: " .$_POST['cust_email_addr']. "\n";
   $mail_boddy .= "\n <br><b>- Customer Phone:</b>: " .$_POST['cust_phone']. "\n";
   
   // Customer Account Information //
   $mail_boddy .= "\n <b>Customer Account Information" '\n';
   $mail_boddy .= "\n <br><b>- Requested Package Type:</b>: " .$_POST['cust_package']. "\n";
   $mail_boddy .= "\n <br><b>- Requested Domain:</b>: " .$_POST['cust_domain']. "\n";
   $mail_boddy .= "\n <br><b>- Requested Password:</b>: " .$_POST['cust_passwd']. "\n";
   $mail_boddy .= "\n <br><b>- Requested Password Confirmation:</b>: " .$_POST['cust_domain']. "\n";
   
// Action for correct or incorrect CAPTCHA code //
   if ($captcha == "no") {
               echo '<script type="text/javascript">';
               echo 'alert("Wrong Validation Code.");';
               echo 'window.setTimeout(window.history.back().0); ';
               echo '</script>'
               }
// Actions to perform after the "Submit" button is pressed //
   if
      ($captcha == "yes")
       mail{$mailto, $mail_subject,$mail_body, $headers);
   if
      ($captcha == "yes"}
      echo '<META HTTP:-EQUIV=Refresh CONTENT="0; URL='http://www.paypal.com'">';         
               
               
thats not the entire code, theres not even a form.

Anyway, from top to bottom i notice the following problems

1) using Session variables without using session_start()
2) using { instead of ( and } instead of ). multiple times
3) possibly misspelt 'capycha'
4) using "no" and "yes" where obviously boolean values are meant
5) missing concenation (sp?) on line $mail_boddy .= "\n <b>Customer Account Information" '\n';
6) misspelt $mail_boddy
7) where is the code that sets S_POST["capycha"]? Where is the code that sets $_SESSION["pass"]?

Also, your code is susceptible to email header injection. I would not post this on a live server.

There are more, but im not going to point out multiple errors of the same kind. Also, get some frigging syntax highlighting!
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Return to Web Design & Development

Who is online

Users browsing this forum: No registered users

cron