Archive for the ‘Php Coding’ Category
The following php function will return an array(0-10) of image URLs.
<?php
/* Returns 10 image URLs array */
function images_search($se, $kw){
$icount=0;
$image =array();
if($se=="Bing"){
$imgs = 'http://www.bing.com/images/search?q='.urlencode(trim($kw));
$imgs = file_get_contents($imgs);
preg_match_all("/<span class="md_mu">(.*?)</span>/is", $imgs, $imgu, PREG_PATTERN_ORDER);
shuffle($imgu[1]);
$iv = array_values($imgu[1]);
for($j=0; $j < count($iv);$j++)
if(strpos($iv[$j],'"')>-1 || strpos($iv[$j],'""')>-1) continue;
elseif(@fclose(@fopen($iv[$j], "r"))){ ÂÂ
$image[$icount]=$iv[$j];
$icount++;
if($icount==10)
break;
}
}else{
$start=rand(0,9)*20+1;
$imgs= 'http://images.google.com/images?gbv=2&hl=en&q='.urlencode(trim($kw)).'&sa=N&start='.$start.'&ndsp=30';
$imgs = file_get_contents($imgs);
preg_match_all("/x3dhttp:(.*?).jpg/is", $imgs, $imgu, PREG_PATTERN_ORDER);
shuffle($imgu[1]);
$iv = array_values($imgu[1]);
for($j=0;$j<count($iv);$j++)
if(strpos($iv[$j],'"')>-1 || strpos($iv[$j],'""')>-1) continue;
elseif(@fclose(@fopen('http:'.$iv[$j].'.jpg', "r"))){ ÂÂ
$image[$icount]='http:'.$iv[$j].'.jpg';
$icount++;
if($icount==10)
break;   ÂÂ
}
}
return $image;
}
?>
Use this function like this:
<?php
// Call function like
$google_images = images_search('Bing', 'doctors');
// or
$bing_images = images_search('Google', 'forex');
?>
Searched By: catchy inurl:/guestbook html?page= (7), tramadol online overnight shipping inurl:/guestbook php?id= (6), inurl:/modules php?op= make signs free (6), addresses inurl:/guestbook pl (6), inurl:/posting php?mode= interracial babies (6), harris inurl:/vb 1/member php?u= (5), inurl:/register php? build (5), 10 minute trainer inurl:/gb asp (4), between inurl:/sign php (4), inurl:/index php?action=stats provided sudoku numbers (4), inurl:/register php centralise (4), including inurl:/guestbook php?newsid= (3), inurl:/modules php?op= doing business in australia (3), inurl:/book php alligatoring (3), inurl:/register php outline (3), 1000 games shooting inurl:/add php (3), inurl:/index php nba stats news (3), munchen inurl:/register intext:upcoming intext:published intext:submit -inurl: php (3), inurl:/write asp agile (3), long inurl:/board_list php?board index= (2)
admin/August 11, 2010/Php Coding/Origin for Knowledge!/ 0 Comments Tags: bing, function, Google, images, php, urls
There are cases when a php developers need to insert mysql data with strings which containing single or double quotes. Mysql gives error or will not save data if we do not properly escape the string formation characters. To escape these characters php have a function {mysql_real_escape_string()}. This function can be used to format the mysql strings with escaping. e.g.
<?php
$escaped_mystring = mysql_real_escape_string($mystring);
?>
Now if you run the query after escaping it will save the string wit out any error.
Searched By: mysql2 escape (3), c# mysql quote (2), mysqldata c# escape (1), php mysql search data single quotes (1), php save quotation single (1), php sql format (1), quote mysql vb6 (1), quote saving c# mysql (1), save quote to mysql (1), SAVE SINGLE QOUTE IN mysql (1), save single quote in php (1), send a string with apostrophe and double quote in php mysql (1), store a string with quotes in mysql (1), using double quotes in mysql query string (1), vb 2010 mysql escape character (1), mysql2 scape (1), c# escape string mysql (1), c# mysql hadling quotes in query text (1), c# quote mysql (1), csharp error mysql double (1)
admin/August 11, 2010/Php Coding/Origin for Knowledge!/ 0 Comments Tags: mysql escaping, mysql escaping function, mysql string error, single and double quotes
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)
admin/March 9, 2010/Php Coding/Origin for Knowledge!/2 Comments Tags: browser, form, php, prevent, reload, resubmit
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)
admin/March 8, 2010/Php Coding/Origin for Knowledge!/6 Comments Tags: file, local server, php, remote server, upload
In some cases php developers don’t have permissions to use php copy function or face difficulty to use it. For that there is a simple way to copy a file from one place to other.
To do so get the contents of the file you want to copy, suppose you have a file, “test.php” and want to copy it. i.e
$copy=file_get_contents(“test.php”);
Next open a new file in the location where you want to copy the file. Suppose you want to copy in the directory “data”, then do as:
$fp=fopen(“data/test.php”,”w”);
This will open a new file in “data” directory with “test.php” name. You can use any other name you want. Now write the file contents to newly open file and close the the file source.
fwrite($fp,$copy);
fclose($fp);
This will write all the content stored in $copy variable to the new file. If you are using this method to move a file then at the end just use the unlink(delete) function to delete the original file. Here is a complete code:
<?php
//File to copy
$copy=file_get_contents(“test.php”);
//where to copy and with what name
$fp=fopen(“data/test.php”,”w”);
fwrite($fp, $copy);
fclose($fp);
//If your are moving file
unlink(“test.php”);
?>
Remember you must have the write permission to “data” directory in order to create new file. i.e chmod 777.
Searched By: php copy alternative (17), alternative to php copy (3), alternative copy function in php (2), php copy vs fwrite (2), php alternative to copy (2), php copy() alternative (1), php copy fwrite (1), php copy alterneti̇ff (1), php alternative zu copy() (1), php alternative copy (1), fwrite alternative php (1), copy function alternative in php (1), alternative to php copy() (1), alternative php copy() (1), alternative of copy in php (1), alternative for copy function in php (1), php non-fopen alternative to copy (1)
admin/March 6, 2010/Php Coding/Origin for Knowledge!/ 0 Comments Tags: php copy function
|
|