Posts tagged ‘php’

Prevent form from being resubmitted on browser reload in PHP

In doing a project for backlinks in php, I came across a problem. When a link is saved in database then if user reload the page, the script re-save the data. So I want a solution that on reloading browser the post data should not save. I searched for it but could not find some proper solution. Here is what i did:


<?php
if(!isset($_REQUEST['ok']))
{
  // database query to save post data...
  Header("Location: same_page.php?ok=true");
}
?>

So when you send header on same page but with a request variable which set now this time, it will not allow the query to save same information again. So on hitting reload the form will not submit and you can also stay on the same page.

Note: If you use this method and do not send a request variable, then it will become infinite loop.

Here are some other to try:

Use a meta refresh,

echo “<meta http-equiv=”refresh” content=”TIME_HERE;url=URL_HERE”>”;

You can also just add a session variable when the form has been submitted successfully. Then on the same time check if the session variable is set before you resubmit the form.

Then it would not matter if the same post data is resubmit, since the session variable would be set.

Searched By:

inurl:/viewthread?thread= powered by vbulletin see description below (7), php do not allow resend (5), touch inurl:/form php (5), inurl:/viewthread?thread= powered by vbulletin entire site updated (5), inurl:/viewthread?thread= powered by vbulletin natural capital includes (4), inurl:/viewthread?thread= powered by vbulletin sell other companies products (4), inurl:/viewthread?thread= powered by vbulletin science writers association (3), inurl:/viewthread?thread= powered by vbulletin replacement programs for itunes (3), inurl:/viewthread?thread= powered by vbulletin discount dance supply discounts (3), powered by vBulletin discount (2), inurl:/viewthread?thread= powered by vbulletin second hand smoke (2), php resubmission (2), inurl:/viewthread?thread= powered by vbulletin engineering company in texas (2), inurl:/pages/forum-thread-form malingerers (2), powered by vBulletin how to check (2), powered by vBulletin engineering services (1), wordpress prevent form resubmission (1), php prevent resubmit session (1), php resend same data (1), php resend stop (1)

File transferring, uploading from one server to other server using php

It is easy to transfer/upload a file from one server to an other from php scripts. You have to use php ftp functions. If you have ftp access to other server(host, username, password), then you can follow following steps to upload a file from your loacl or from remote server to any other server.

1.First connect to the server where you want to send the file as:

$ftp=ftp_connect(“ftp.yourdomain.com”);

This will connect your php script to the other server.

2.Now open the file which you want to transfer or upload as:

$fp=fopen(‘myimage.jpg’, “r”);

You can open any file even any remote file using full file path.

3.Now login to ftp host using “username” and “password”.

ftp_login($ftp, “username”, “password”);

4.Now upload the file as:

ftp_fput($ftp, “public_html/myimage.jpg”, $fp, FTP_BINARY);

This function will put the file in public_html folder with same file name but you can use any name instead of “myimage.jpg”, the file will transfer with new name.

5.At end close ftp and opened file.
ftp_close($ftp);
fclose($fp);

Note: Here you need to specify the “public_html” folder name as most ftp give access to the main cPanel folder but if your ftp direct login in “public_html” then you don’t need to specify the “public_html” folder, just put file name. If you you are upolading file to any internal folder then you specify that folder name. Suppose you want upload the file to images folder then follow this:

ftp_fput($ftp, “public_html/images/myimage.jpg”, $fp, FTP_BINARY);

Full Code:

<?php

// Connect to ftp host

$ftp=ftp_connect(“ftp.yourdomain.com”);

// Open the file which is to be transfer

$fp=fopen(‘myimage.jpg’, “r”);

// Login to ftp host

ftp_login($ftp, “username”, “password”);

// Transfer the file in the “public_html” folder

ftp_fput($ftp, “public_html/myimage.jpg”, $fp, FTP_BINARY);

// Close ftp and opened file

ftp_close($ftp);
fclose($fp);

?>

Searched By:

inurl:/viewthread?thread= powered by vbulletin remote camera systems (3), term inurl:/guestbook html?page= (2), inurl:/guestbook php?new_message= amante (2), shared php server copy with http (1), send pwd ftp c sharp (1), script to move files from one directory to another within the ftp-server c# (1), saving files from one website to another website c# (1), save file to folder remote server c# (1), sample ftp file transfer script to another computer (1), remotely move a file from server to server (1), remotely copy files remote computer in c# (1), powered by vBulletin free ftp software (1), powered by vBulletin client server software (1), soap remote file uploade (1), “powered by vbulletin” contractor mortgages (1), transfer file to another computer using c# net (1), write the files from server using c# (1), vb6 store file remote server (1), vb6 file another computer login (1), vb6 copy to remote server (1)