wp_redirect Code Snippet Error - error with ; - redirect

I am trying to do if person is member of woocommerce membership, if is page x, then redirect to new url. If I add this as a code snippet I get
The code snippet you are trying to save produced a fatal error on line 5:
syntax error, unexpected ';'
function redirect_custom(){
ob_clean();
ob_start();
if (is_page( array( 215230 ) ) && wc_memberships_is_user_active_member($user_id, 'membership-club') {
wp_redirect( "http://www.example.com/contact-us", 301 );
exit();
}
}
add_action( 'template_redirect', 'redirect_custom');

Related

Cakephp mail sending error

I am getting the following error while sending mail from on localhost through my application:
Strict (2048): Only variables should be passed by reference
[CORE\Cake\Network\Email\SmtpTransport.php, line 217]
The mail gets sent but an error is thrown and the screen does not redirect. I just want to get rid of this error.
I am posting the code from line 217 onwards.
$response = end(explode("\r\n", rtrim($response, "\r\n")));
if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) {
if ($code[2] === '-') {
continue;
}
return $code[1];
}
throw new SocketException(__d('cake_dev', 'SMTP Error: %s', $response));
The email code is below.
$email = new CakeEmail();
$email->config('gmail');
$email->viewVars(array('userfname'=>$data['User']['username']));
$email->viewVars(array('userlname'=>$data['User']['username']));
$email->viewVars(array('username'=>$data['User']['username']));
$email->template('welcome')
->emailFormat('html')
->sender('amitagarwal_dce#rediffmail.com', 'MyApp emailer')
->from(array('me#example.com' => 'CC'))
->to($data['User']['username'])
->bcc(array('atkral11#gmail.com'))
->subject('Thankyou for applying with us')
->send();
Any help is appreciated.

php form processing issue when processing script returns to the calling script

Problem:
form processing script throws error when returning back to the calling script which is the user entry form.
error message
Notice: A session had already been started - ignoring session_start() in /inc/utilities.inc.php on line 3 Fatal error: Cannot redeclare class Connection in /inc/dbconn.php on line 5
The code is a bit too large to copy past all of it so im just going to focus on the problem area.
newproject.php calls -> savenewproject.php. if savenewproject.php finds error it returns back to newproject.php to display error message.
//newproject.php - parts of the code that i believe is the problem area.
<?php
include('../inc/utilities.inc.php');
include('header.php');
if (!empty($errorString))
{ echo '<div class="error">' . $errorString . '</div>'; }
if (!empty($successString))
{ $emailaddress = '';
$budget = '';
$projecttitle ='';
$projectdescription = '';
echo '<div id="divfadeout" class="success">' . $successString . '</div>';
}
?>
<form name ='newProject' action="../inc/savenewproject.php" enctype="multipart/form-data" method="POST">
the rest are form fields
</form>
// include('../inc/utilities.inc.php'); - appears in both script
<?php
session_start();
$user = (isset($_SESSION['user'])) ? $_SESSION['user']: null;
include("../inc/dbconn.php");
?>
// savenewproject.php - copy/pasting what i believed to be the problem area.
if(count($fieldErrors) > 0)
{ $errorString = '<p>There was an error processing the form.</p>';
$errorString . 'ul>';
foreach($fieldErrors as $errorVal)
{ $errorString .= "<li>$errorVal</li>"; }
$errorString .= '</ul>';
include ('../layout/newproject.php');
}
else
{
looks like i answered my own question..
instead of include i used request once and it seems to have fixed the probelm..

open_basedir restriction in effect. File() is not within the allowed path(s) and Uncaught CurlException: 3: No URL set! thrown in base_facebook.php

protected function makeRequest($url, $params, $ch=null) {
if (!$ch) {
$ch = curl_init();
}
$opts = self::$CURL_OPTS;
if ($this->useFileUploadSupport()) {
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
}
$opts[CURLOPT_URL] = $url;
// disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
} else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
self::errorLog('Invalid or no certificate authority found, '.
'using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}
if ($result === false) {
$e = new FacebookApiException(array(
'error_code' => curl_errno($ch),
'error' => array(
'message' => curl_error($ch),
'type' => 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
return $result;
}
I have built a facebook app, but something went wrong in this piece of code of base_facebook.php.
Whole code is here. All i get everytime are this 2 errors -
1.Warning: curl_setopt_array() [function.curl-setopt-array]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/a2424901/public_html/base_facebook.php on line 802
2.Uncaught CurlException: 3: No URL set! thrown in /home/a2424901/public_html/base_facebook.php on line 814
Here is the code of my facebook app i.e.(index.php)
Yeap, non-obvious error message.
But it means, that realpath() returns empty value:
File() is not within the allowed path(s)...
Make sure, that the file passed to realpath() function really exists in the specified path.
Other exceptions in your example were caused by this problem.
By the way, it's good practice to wrap all weak spots (in your example - Facebook API calls) in try-catch blocks.

Twitter RSS feed, [domdocument.load]: failed to open stream:

i'm using the following:
<?php
$doc = new DOMDocument();
$doc->load('http://twitter.com/statuses/user_timeline/XXXXXX.rss');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
}
for($i=0;$i<=3;$i++) {
$tweet=substr($arrFeeds[$i]['title'],17);
$tweetDate=strtotime($arrFeeds[$i]['date']);
$newDate=date('G:ia l F Y ',$tweetDate);
if($i==0) { $b='style="border:none;"'; }
$tweetsBox.='<div class="tweetbox" ' . $b . '>
<div class="tweet"><p>' . $tweet . '</p>
<div class="tweetdate">#' . $newDate .'</div>
</div>
</div>';
}
return $tweetsBox;
?>
to return the 4 most recent tweets from a given timeline (XXXXX is the relevant feed)
It seems to work fine but i've recently been getting the following error sporadically:
PHP error debug
Error: DOMDocument::load(http://twitter.com/statuses/user_timeline/XXXXXX.rss) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.1 502 Bad Gateway
I've read that the above code is dependant on Twitter beign available and I know it gets rather busy sometimes. Is there either a better way of receiving twits, or is there any kind of error trapping i could do to just to display "tweets are currently unavailable..." ind of message rather than causing an error. I'm usnig ModX CMS so any parse error kills the site rather than just ouputs a warning.
thanks.
I know this is old, but I was just searching for the same solution for a nearly identical script for grabbing a twitter timeline. I ended up doing this, though I haven't been able to thoroughly test it.
I defined the twitter url as a variable ($feedURL), which I also used in $doc_load. Then, I wrapped everything except for the $feedURL into this conditional statement:
$feedURL = "http://twitter.com/statuses/user_timeline/XXXXXXXX.rss"
$headers = #get_headers($feedURL);
if (preg_match("/200/", $headers[0])){
//the rest of you original code in here
}
else echo "Can't connect user-friendly message (or a fake tweet)";
So, it's just checking the headers of the the feed's page, and if its status is 200 (OK), then the rest of the script will execute. Otherwise, it'll echo a message of your choice.
(reference: http://www.phptalk.com/forum/topic/3940-how-to-check-if-an-external-url-is-valid-andor-get-file-size/ )
ETA: Or even better, save a cached version of the feed (which will also ensure you don't go over your API limit of loads):
<?php
$cache_file = dirname(__FILE__).'/cache/twitter_cache.rss';
// Start with the cache
if(file_exists($cache_file)){
$mtime = (strtotime("now") - filemtime($cache_file));
if($mtime > 600) {
$cache_rss = file_get_contents('http://twitter.com/statuses/user_timeline/75168146.rss');
$cache_static = fopen($cache_file, 'wb');
fwrite($cache_static, $cache_rss);
fclose($cache_static);
}
echo "<!-- twitter cache generated ".date('Y-m-d h:i:s', filemtime($cache_file))." -->";
}
else {
$cache_rss = file_get_contents('http://twitter.com/statuses/user_timeline/75168146.rss');
$cache_static = fopen($cache_file, 'wb');
fwrite($cache_static, $cache_rss);
fclose($cache_static);
}
//End of caching
?>
Then use $cache_file in your $doc->load($cache_file) statement instead of the actual feed url.
(Adapted from here: http://snipplr.com/view/8156/twitter-cache/).

Get current logged user is throwing exception in joomla

I am trying this in Joomla
, but i getting error
Catchable fatal error: Object of class JUser could not be converted to string in C:\xampp\htdocs\Joomla\components\com_jumi\jumi.php(25) : eval()'d code on line 3
Try below instead of your code.
<?php
$user =& JFactory::getUser();
print_r($user);
?>
This will work because the first line will return the object and you are trying to print the object using echo.
If you want to get user name the try below code.
<?php
global $mainframe;
$User_name = $mainframe->getuser()->get('name');
?>
above code will return name of the logged in user.