How to add email function to this php checking script? [closed] - php

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How to add email function to send if the port isnt responding (false) to this script below ?
<?php
function test_port($host,$port=80,$timeout=6)
{
$fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
if ( ! $fsock )
{
return FALSE;
}
else
{
return TRUE;
}
}
/* check our website http://www.example.com is up and running (port 80) and timeout after 20 seconds */
$ok = test_port('IP/website',80,20);
?>

The simplest way would be replacing return FALSE; with an appropriate call to the PHP mail function
EDIT: this solves the mail() poblem, but note that fsockopen might not be the right way to detect if a host is up. This question could be a good starting point.

Related

Custom error message for input [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to set a custom message for an input:
$this->form_validation->set_message('username', 'Choose a business, Mang!');
and display this:
<?php echo form_error('username'); ?>
But nothing displays for me, what is wrong?
Is this what I need? Example:
if($result)
{
$this->form_validation->set_message('username', 'Choose a business, Mang!');
}
You need to set rules as such:
$this->form_validation->set_rules('form_field_username', 'username', 'required|callback_business_check');
function business_check($username) {
if(strlen($this->input->post('form_field_business')) == 0) {
$this->form_validation->set_message('business_check', 'Choose a business, Mang!');
return false;
}
return true;
}
This is providing I have the right idea of what you are doing...

How to get latest Tweets of an User [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to get my client latest tweets. After Searching in Google i got some code. Unfortunately the code is working in localhost, But not working in the Hosting server. Its saying couldn't find the server. I am posting the code snapshot..
<?php
function getTwitterStatus($userid){
$url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1";
$xml = simplexml_load_file($url) or die("could not connect");
foreach($xml->status as $status){
$text = $status->text;
}
echo $text;
}
//my user id AmitEducation
getTwitterStatus("AmitEducation");
?>
Please help me out. If anyone have better suggestion please help me.
Use the Twitter Search API, it's really awesome. And it's JSON. [+1]
$tweets = json_decode(file_get_contents("http://search.twitter.com/search.json?q=php&rpp=5&include_entities=true&result_type=mixed"));
foreach($tweets->results as $t){
echo "Username: {$t->from_user_name}";
echo "Tweet: {$t->text}" . PHP_EOL;
}
Please read the documentation for how to use and see examples.
change the username in the link
<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/username.json?count=10", true); //getting the file content
$decode = json_decode($json, true); //getting the file content as array
print_r($decode);
?>

How can I use $_GET in the same page [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
My pseudo code is as follows:
if($_GET['action'] == 'list'){
do function getFileList($dir)
else
do nothing
exit;
}
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
}
Your psuedo code is almost there.
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
/* ... */
}
if($_GET['action'] == 'list') {
getFileList($dir);
}
Are you asking how to send a variable via GET to a PHP file from within the same PHP file? You can create a form that submits to itself: http://www.tellingmachine.com/post/Simple-self-submitting-PHP-forms.aspx.
If you are looking to do something else, please provide additional details.

How can I use PHP to automatically change the page if [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
...the conditions of an if statement are fulfilled?
I have some code to add data to a database if certain conditions are met, after the data is added I want the page to redirect to another page? How can I do this?
Use if-else condition. You can use header() of PHP .
if(/* Your conditions */){
// redirect if fulfilled
header("Location:nxtpage.php");
}else{
//some another operation you want
}
You shoul use header php function
<?php
//some conditions
header("Location: http://www.example.com/");
?>
try this code
$query ="insert into test values (1,'test')";
if(mysql_query($query) == true)
{
header('location:index.php');
exit();
}
else
{
echo " insert failed";
}
Try PHP Header:
header('Location: http://www.example.com/');

PHP - Contact form sent message [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I found a great contact form over here. How to show a "Successfully sent" message right under the contact from instead of using a redirect to an other page?
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
Change the form process code to this.
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
$successful = false;
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$successful = true;
}
}
Where you want the message to show.
if($successful){
echo "Successfully sent.";
}

Categories