verifying cookies

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 700 Views - Last Post: 25 February 2014 - 03:52 PM

#1 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

verifying cookies

Posted 24 February 2014 - 12:31 PM

So I am kind of new to javascript and well I have two questions, my first one is in regards to cookies. I am trying to great a vote poll that when someone votes they cannot vote again until the next day. I want to do this using cookies. Basically it makes a cookies and then checks to see if that cookie is there when they try to vote again and if it is that redirect them to another page. I managed to get this to work on internet explorer but when I try to do it on firefox or chrome it does not work, am I suppose to write it differently for firefox and chrome. here is my code:

<!DOCTYPE html>
<html>
<body>

<script type="text/javascript">
var expiration = new Date();
expiration.setDate(expiration.getDate() + 2);

// add cookie "done=true" with expiration
document.cookie="done=true;expires=" + expiration.toUTCString();

var count = 0;
var myCookie = document.cookie.split(';').filter(function(item) { 
   	if (item.split('=')[0] == 'done')
		return count = 1;	
});

if (count > 0) {
    window.location = "test3.html";
}
</script>

<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>

</body>
</html>



And my other question is with emails. I want a way to add a upload box where people can email a file to my email which is a hotmail or gmail. Is there anyway to do that? Please let me know. Thank you in advanced.

Is This A Good Question/Topic? 0
  • +

Replies To: verifying cookies

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,660
  • Joined: 12-December 12

Re: verifying cookies

Posted 24 February 2014 - 12:49 PM

The first thing to check is whether cookies are enabled in those browsers.

Then check your browser's console for any errors. There are links for the various consoles in my signature; in some pressing F12 will open the developer tools, and error messages are normally in the bottom-right corner.

Array.filter() isn't supported in some older browsers. There is a polyfill here but it isn't needed for modern browsers.

For emailing a file you'll need an HTML upload-form and a server-side script to process the form and forward the email.
Was This Post Helpful? 0
  • +
  • -

#3 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 24 February 2014 - 01:11 PM

Ive checked that, the cookie gets stored on both internet explorer and firefox, however when it comes to redirecting for checking if the cookies exists firefox doesnt do that, while explorer does, so that rules out any errors that might be in the code as well that cookies are enabled, and i know its not the browser becuase ive updated to the latest browser and have tried my code on other computers to see if maybe something was up with mine, so my guess is that its something to do with the way firefox is reading my code, maybe its coded differently for firefox? So thats why im wondering if anyone has an example of how it should be written in firefox or if they can see something wrong with my code.

Also for my question with the email, ive done reaserch and yes i know i need an upload form and server side script im wondering if i can make it so that it sends the emails to my hotmail instead of having to purchase a domain email address and get it to send it there.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,660
  • Joined: 12-December 12

Re: verifying cookies

Posted 24 February 2014 - 01:59 PM

I can't test this currently but I am suspicious about this:
        return count = 1;

The return value within filter() should be true or false, although 1 will be considered true. This is used to determine only whether to include the element in the filtered array.

I would remove the assignment to count within this filter function, and check the length of the array myCookie afterwards, to determine whether the value was found.

But filter() is overkill and you could just use some() to determine if the cookie exists.

I'm guessing you can forward to Hotmail although you'll need to check with your host.
Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 322
  • View blog
  • Posts: 1,182
  • Joined: 15-January 14

Re: verifying cookies

Posted 24 February 2014 - 03:54 PM

Quote

however when it comes to redirecting for checking if the cookies exists firefox doesnt do that, while explorer does, so that rules out any errors that might be in the code

That doesn't rule out anything. The way you rule out any possible errors is by looking in the developer console for error messages. If you're assuming that there is not an error because of what the browser is doing or not doing, then that's a problem. Don't assume, verify.
Was This Post Helpful? 1
  • +
  • -

#6 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 25 February 2014 - 08:08 AM

Ok so I still havnt figured out the cookies issue, but my mail problem ive almost got it working my problem now is that when i try to attach a file it tells me "File could not be access" but then the rest of the message sends. So i am writing something wrong for the attachment part. Here is my code, i hope someone can find the answer.

<?php
if(isset($_POST['submit'])) 
{

$message=
'Full Name:	'.$_POST['fullname'].'<br />
Subject:	'.$_POST['subject'].'<br />
Phone:	'.$_POST['phone'].'<br />
Email:	'.$_POST['emailid'].'<br />
Comments:	'.$_POST['comments'].' <br> />
';
    require "phpmailer/class.phpmailer.php"; //include phpmailer class
      
    // Instantiate Class  
    $mail = new PHPMailer();  
      
    // Set up SMTP  
    $mail->IsSMTP();                // Sets up a SMTP connection  
    $mail->SMTPAuth = true;         // Connection with the SMTP does require authorization    
    $mail->SMTPSecure = "ssl";      // Connect using a TLS connection  
    $mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
    $mail->Port = 465;  //Gmail SMTP port
    $mail->Encoding = '7bit';
    
    // Authentication  
    $mail->Username   = "youremail@gmail.com"; // Your full Gmail address
    $mail->Password   = "yourpassword"; // Your Gmail password
      
    // Compose
    $mail->SetFrom($_POST['emailid'], $_POST['fullname']);
    $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
    $mail->Subject = "New Contact Form Enquiry";      // Subject (which isn't required)  
    $mail->MsgHTML($message);
	$mail->AddAttachment( $Attachment , 'Titanfall.txt');
 
    // Send To  
    $mail->AddAddress("recipientemail@gmail.com", "Recipient Name"); // Where to send it - Recipient
    $result = $mail->Send();		// Send!  
	$message = $result ? 'Successfully Sent!' : 'Sending Failed!';      
	unset($mail);

}
?>
<html>
<head>
  <title>Contact Form</title>
</head>
<body>
					
		<div style="margin: 100px auto 0;width: 300px;">
			<h3>Contact Form</h3>
			<form name="form1" id="form1" action="" method="post">
					<fieldset>
					  <input type="text" name="fullname" placeholder="Full Name" />
					  <br />
					  <input type="text" name="subject" placeholder="Subject" />
					  <br />
					  <input type="text" name="phone" placeholder="Phone" />
					  <br />
					  <input type="text" name="emailid" placeholder="Email" />
					  <br />
					  <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea>
					  <br />
					  <INPUT TYPE="file" NAME="attachedfile" MAXLENGTH=10240000 placeholder="Attachment" > 
					  <br />
					  <input type="submit" name="submit" value="Send" />
					</fieldset>
			</form>
			<p><?php if(!empty($message)) echo $message; ?></p>
		</div>
					
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#7 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 322
  • View blog
  • Posts: 1,182
  • Joined: 15-January 14

Re: verifying cookies

Posted 25 February 2014 - 11:18 AM

$mail->AddAttachment( $Attachment , 'Titanfall.txt');



You haven't defined $Attachment. That needs to be the path of the file you want to attach.
Was This Post Helpful? 0
  • +
  • -

#8 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 25 February 2014 - 11:28 AM

I want it to be that the browse button shows up and then they choose the file and add it.
Was This Post Helpful? 0
  • +
  • -

#9 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 322
  • View blog
  • Posts: 1,182
  • Joined: 15-January 14

Re: verifying cookies

Posted 25 February 2014 - 11:41 AM

That's fine, then you need to use PHP to validate and process the file upload. There's a short tutorial here:

http://www.w3schools...file_upload.asp

and information in the manual:

http://www.php.net/file_upload
Was This Post Helpful? 0
  • +
  • -

#10 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 25 February 2014 - 12:22 PM

$mail->AddAttachment($_FILES['attachedfile']);


i did but it still is not working, it keeps saying "can't access file:"
Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 322
  • View blog
  • Posts: 1,182
  • Joined: 15-January 14

Re: verifying cookies

Posted 25 February 2014 - 01:58 PM

$_FILES['attachedfile'] is an array, not the filename. It is an array of information about the uploaded file. The tutorials show that.
Was This Post Helpful? 0
  • +
  • -

#12 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 25 February 2014 - 02:13 PM

$mail->AddAttachment($_FILES['file']['name']);


yea so now ive put that, but still it does not work, i just want the file to be sent as an attachment which ever file they attach. But it keeps telling me it cannot access file: what am I suppose to write there?

This post has been edited by Brandon222: 25 February 2014 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

#13 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,660
  • Joined: 12-December 12

Re: verifying cookies

Posted 25 February 2014 - 02:40 PM

$_FILES['file']['name']

This is just the name of the file.

I don't use PHPMailer but I believe this code should work:
if (isset($_FILES['uploaded_file']) &&
    $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
                         $_FILES['uploaded_file']['name']);
}

which sends the uploaded file from its temporary server location.

This temporary file will disappear when the script ends. If you need to save the file on the server then re-read the previously given links to save the uploaded file before sending it as an attachment.

An alternative, more advanced, approach is given in this sitepoint link. This doesn't save the file to the server (it just reads and sends the file-data) but, if you don't need to save it, then the PHPMailer code above should do the job, I believe.
Was This Post Helpful? 0
  • +
  • -

#14 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 25 February 2014 - 02:56 PM

Ok so that stopped giving me an error, but when i check the email that it sent, theres nothing in there. The attachment doesnt go through.
Was This Post Helpful? 0
  • +
  • -

#15 Brandon222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 16-November 08

Re: verifying cookies

Posted 25 February 2014 - 03:16 PM

actually no looking it at, it still doesnt work and still gives me the same error. I dont know if its not grabbing the right file or not the right place. I cant seem to figure it out or find it anywhere.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2