Redirecting URL in WordPress - regex

I want to redirect a URL in the form of
http://a_domain_name.com/2013/08/link_name/feed to http://a_domain_name.com/link_name/feed. I am a WordPress beginner and finding it hard to do this . Whats the best way to do this ?
I tried using the safe redirection plugin with http://domain_name.com/%year%/%monthnum%/%postname%/feed to http://domain_name.com/%postname%/feed but it's not working

The Proper Way
Log into wordpress admin panel and go to the settings>permalinks page.
From here, select the second to last option, ie:
http://domain.com/blogname/blog/sample-post/
Alternatively, you can create a redirect file. This involves hacking up wordpress a bit. I wouldn't recommend this if you're not comfortable with wordpress & php. To do this, first:
Open the setting>permalinks page in the admin panel:
Select the last option in the list (custom) and enter something like this:
/redirect.php?p=%post_id%&a=%author%&c=%category%
You'll also need to change the two optional forms below to:
Category base
/redirect.php?c=
Tag base
/redirect.php?t=
Now, let's create a redirect php file. Place this in /yourblogname/blog/
<?php
$total=0;
$string = 'http://www.yourdomain.com/';
$fetch = '';
if (isset($_GET['p'])&&!is_null($_GET['p']))
{
$p = $_GET['p'];
if ($total ==0) {
$string.='?p='.$p;
} else {
$string.='&p='.$p;
}
$total++;
}
if (isset($_GET['t'])&&!is_null($_GET['t']))
{
$t = str_replace('/','',$_GET['t']);
if ($total ==0) {
$string.='?tag='.$t;
} else {
$string.='&tag='.$t;
}
$total++;
}
if (isset($_GET['a'])&&!is_null($_GET['a']))
{
$a = $_GET['a'];
if ($total ==0) {
$string.='?a='.$a;
} else {
$string.='&a='.$a;
}
$total++;
}
if (isset($_GET['s'])&&!is_null($_GET['s']))
{
$s = $_GET['s'];
if ($total ==0) {
$string.='?s='.$s;
} else {
$string.='&s='.$s;
}
$total++;
}
if (isset($_GET['c'])&&!is_null($_GET['c']))
{
$c = str_replace('/','',$_GET['c']);
if ($total ==0) {
$string.='?category_name='.$c;
} else {
$string.='&category_name='.$c;
}
$total++;
}
echo '<head><meta http-equiv="Refresh" content="0; URL='.$string.'">';
?>
<style>
html {
background:black;
color:white;
}
</style>
</head>
<body>
<div id=cont>
<p align=center><div style='font-size:72px;text-align:center;' ><?php echo "redirecting..."; ?></p></div>
</div>
</body>
We're not done yet. We need to adjust the page we're redirecting to now... (index.php)
if (!isset($_GET['p'])) {
if (!isset($_GET['category_name']) && !isset($_GET['tag']) && !isset($_GET['s']) && !isset($_GET['search']) ) {
include('newhome.php'); //frontpage with no special redirect
} else {
include('listabbrposts.php'); //a list of abbreviated posts for browsing
}
} else {
include('entry.php'); // a page with a single article
}
For a working example, you can check out my page where I use this technique: http://www.artfuladvection.com click on a topic or tag from the left to see the redirect.

Related

Link that automatically fills a field on the target page

How can I construct a URL that will automatically fill in a field on the target page?,
I tried already https://www.mywebsite.com/index.php?route=account/register?name=firstname to fill first name on registration form, but for opencart it won't work, so please tell me what I missing here?
Thank you.
In this file:
catalog\controller\account\register.php
Find:
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
Change it to:
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else if (isset($this->request->get['name'])) {
$data['firstname'] = $this->request->get['name'];
} else {
$data['firstname'] = '';
}

Cant log in to my wrbsite and cant find a mistake in elseif

What can be wrong? cant seem find the mistake getting login=error but cant see what i wrote wrong in my last code part with elseif or maybe its not eelseif but if i not getting username or passwords or empty error it must be the last part or iam wrong ? but i dont know hot to solve it please help me.
<?php
session_start();
if (isset($_POST['submit'])) {
include 'dbh.inc.php';
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
if (empty($uid) || empty($pwd)) {
header("Location: ../index.php?login=empty");
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck < 1) {
header("Location: ../index.php?login=username error");
exit();
} else {
if ($row = mysqli_fetch_assoc($result)) {
$hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
if($hashedPwdCheck == false) {
header("Location: ../index.php?login=password error");
exit();
} elseif ($hashedPwdCheck == true) {
//Log in the user here
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../index.php?login=success");
exit();
}
}
}
}
} else {
header("Location: ../index.php?login=error");
exit();
}
It means "submit" is not set.
What is your submit button's name?
Change it to this:
<input type="submit" value="Submit" name="submit" />
the name="submit" is important

what is the code for other browser in vtigercrm

this works only in IE
what is the code,if we want to use mail merge feature in other browser
<script>
if (window.ActiveXObject){
try
{
ovtigerVM = eval("new ActiveXObject('vtigerCRM.ActiveX');");
if(ovtigerVM)
{
var filename = "<?php echo $filename?>";
if(filename != "")
{
if(objMMPage.bDLTempDoc("<?php echo $site_URL?>/test/wordtemplatedownload/<?php echo $filename?>","MMTemplate.doc"))
{
try
{
if(objMMPage.Init())
{
objMMPage.vLTemplateDoc();
objMMPage.bBulkHDSrc("<?php echo $site_URL;?>/test/wordtemplatedownload/<?php echo $datafilename ?>");
objMMPage.vBulkOpenDoc();
objMMPage.UnInit()
window.history.back();
}
}catch(errorObject)
{
document.write("Error while processing mail merge operation");
}
}else
{
document.write("Cannot get template document");
}
}
}
}
catch(e) {
document.write("Requires to download ActiveX Control from vtigerCRM. Please, ensure that you have administration privilage");
}
}
</script>
Simply you can't, cause of the ActiveX Control.
But on github, there is a mod to accomplish the same task, generating an OpenOffice Document (compatible with Word).
It works only on vtiger 5.4
https://github.com/tsolucio/corebos/commit/21a33c071777a312ca6ce11e4b13889994dc52a4

HowTo: send app request, and get data from request (to redirec to to a specific link) without user accepting the app?

let's say user send app requests to his friends,
this request will be targeting something /my_app/catalog.php?ID=25
(not the index page)
the only way to store specific link in app request is to use "data" field of the request.
when user follow app request it will end up on index.php (not catalog.php?ID=25)
how could i extract data field from request without knowing user id? (and without him accepting the app ?)
i can get request_ids and also app_token (not user_access_tocken)
by using
https://graph.facebook.com/oauth/access_token?client_id=".$GLOBALS['app_id']."&client_secret=".$GLOBALS['app_secret']."&grant_type=client_credentials
but without the user id and him accepting the app it is impossible to get "data" field
so instead of user been able to see a product in my app that his friend recommended him , he sees auth forms and accept the app dialogs whiout knoing what is this app about.
this is not a right behavor and to my undestanding first user had to see a link on my page and later on if he want to do actions or my app need permissions for user's info - only when should the "accept dialog" be used.
UPDATE:
I guess Juicy right and where is no other way to get app request url but to either store it in your own database or require user to accept the app
in case if someone else looking for this workaround
here is some usefull stuff:
//to deal with app requests: (this is part of overall page output preparation)
$rqlink="";
if((strlen($_REQUEST['request_ids'])>0)&&(strlen($user->id)>0))//user is logged no need for database
{
if(($rq=getfbres("https://graph.facebook.com/?ids=".$_REQUEST['request_ids']."&access_token=".$_SESSION['access_token'] ))!==false)
{
$rqj = json_decode($rq);
$request_ids = explode(',', $_REQUEST['request_ids']);
foreach ($request_ids as $request_id)
{
$full_request_id=$request_id.'_'.$user->id;
if(isset($rqj->$request_id->data)) $rqlink=$rqj->$request_id->data;
//if(getfbres("https://graph.facebook.com/$full_request_id?method=delete&access_token=".$_SESSION['access_token'])===false)
//{ echo "delete request error:". $GLOBALS['err']; exit;}
break;
}
}
}
elseif(strlen($_REQUEST['request_ids'])>0) //user is not logged, try to extract url from database
{
$request_ids = explode(',', urldecode($_REQUEST['request_ids']));
foreach ($request_ids as $request_id)
{
if(!isset($conn)){include_once "conn.php"; $conn=init_conn();}
if(!($rez=mysql_query("select * from ff_app_rq where rq='".str_replace("'","''",$request_id)."'",$conn))) die ("Database error");
if(mysql_num_rows($rez)>0)
{
$row=mysql_fetch_assoc($rez);
$rqlink=$row['url'];
mysql_free_result($rez);
break;
}
else //request not found for some reason and user is not authorized
{ //force pop-up authorization in order not to loose req_ids
mysql_free_result($rez);
echo("<script LANGUAGE='javascript'>window.open('/fblogin.php','_blank','width=900,height=450');</script>");
break;
}
}
}
if(strlen($rqlink)>0)
{
session_write_close();
echo("<script LANGUAGE='javascript'>document.location.href='".$rqlink."';</script>");
// echo("<script LANGUAGE='javascript'>top.location.href='http".(getenv("HTTPS") == 'on'?"s":"")."://apps.facebook.com/".$GLOBALS['app_namespace']."/".$rqlink."';</script>");
exit;
}
this is how you promote:
function fire_promo()
{
FB.init({appId:'<?php echo $GLOBALS['app_id'];?>',status:true,cookie:true,frictionlessRequests:true,oauth:true});
//(this will display popup with list of fb friends)
getpage('ajforms.php?ID=<?php echo $id;?>&stage=promote_app','subcontent,-100,10,560,500,2,zzz');
return false;
}
function sendRequestToManyRecipients()
{
var f=document.send_inv; //(this form lists all checked users)
var ids="";
for(var z=0;z<f.length;z++) if(f[z].name=='p') if(f[z].checked) {if(ids.length>0) ids+=',';ids+=f[z].value;}
FB.ui({method:'apprequests',data:'catalog.php?ID=<?php echo $id;?>',message:'You have been invited to bla-bla',to:"'"+ids+"'"}, requestCallback);
}
here is app request javascript callback:
function requestCallback(response)
{
if(response === undefined) return;
//if(response.request===undefined) return;
var req = getconn(); if(req) {req.open("HEAD",'fb_req.php?rq='+response.request+'&url='+encodeURIComponent('catalog.php?ID=<?php echo $id;?>',true));req.send(null);}
//console.log(response.request);
if(response.to.length === undefined) {} else if(response.to.length>0) alert('You have successfully promoted to '+response.to.length+' friends.\nThank You!');
}
(getconn is a standart ajax function to initialize ajax communications)
here is fb_req.php to log app requests:
<?php
if((strlen($_REQUEST['rq'])>0)&&(strlen($_REQUEST['url'])>0))
{
include_once "conn.php";
$conn=init_conn();
$rez=mysql_query("insert into my_app_rq_table (rq,url,rq_date) VALUES('".str_replace("'","''",$_REQUEST['rq'])."','".str_replace("'","''",urldecode($_REQUEST['url']))."',now())",$conn);
//if(!$rez) die ("Database error".mysql_error());
}
exit;
?>
and finnaly here is fblogin.php for pop-up authorization and when refreshing opener window:
<?php
session_start();
include_once "params.php";
$code = $_REQUEST["code"];
if(strlen($code)>2)
{
$my_url = "http".(getenv("HTTPS")=='on'?"s":"")."://".getdom().((($_SERVER['SERVER_PORT']=="80")||($_SERVER['SERVER_PORT']=="443"))?(""):(":".$_SERVER['SERVER_PORT']))."/fblogin.php?fb_redirect_url=".urlencode($_REQUEST['fb_redirect_url']);
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$GLOBALS['app_id']."&redirect_uri=".urlencode($my_url)."&client_secret=".$GLOBALS['app_secret']."&code=".$code;
$access_token = getfbres($token_url);
$graph_url = "https://graph.facebook.com/me?".$access_token;
$rr=strpos($access_token,"&");
if($rr>0) $access_token=substr($access_token,0,$rr);
$access_token=str_replace("access_token=","",$access_token);
$user = json_decode(getfbres($graph_url));
if(strlen($user->id)>0)
{
$_SESSION['access_token']=$access_token;
if(strlen($_REQUEST['fb_redirect_url'])>0)
echo "<SCRIPT LANGUAGE='javascript'>\nwindow.opener.location.href='".urldecode($_REQUEST['fb_redirect_url'])."';\nwindow.close();</script>";
else
echo "<SCRIPT LANGUAGE='javascript'>\nwindow.opener.location.reload(true);\nwindow.close();</script>";
exit;
}
}
if(strlen($_SESSION['access_token'])>2)
{
$graph_url = "https://graph.facebook.com/me?access_token=".$_SESSION['access_token'];
$user = json_decode(getfbres($graph_url));
if(strlen($user->id)>0)
{
if(strlen($_REQUEST['fb_redirect_url'])>0)
echo "<SCRIPT LANGUAGE='javascript'>\nwindow.opener.location.href='".urldecode($_REQUEST['fb_redirect_url'])."';\nwindow.close();</script>";
else
echo "<SCRIPT LANGUAGE='javascript'>\nwindow.opener.location.reload(true);\nwindow.close();</script>";
exit;
}
}
$my_url = "http".(getenv("HTTPS")=='on'?"s":"")."://".getdom().((($_SERVER['SERVER_PORT']=="80")||($_SERVER['SERVER_PORT']=="443"))?(""):(":".$_SERVER['SERVER_PORT']))."/fblogin.php?fb_redirect_url=".urlencode($_REQUEST['fb_redirect_url']);
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id=".$GLOBALS['app_id']."&redirect_uri=".urlencode($my_url).$GLOBALS['app_scope'];
//echo "<h1>".$_SESSION['log_attempts']."</h1>";
$_SESSION['log_attempts']=intval("0".$_SESSION['log_attempts'])+1;
if(intval("0".$_SESSION['log_attempts'])<5)
echo("<script>document.location.href='".$dialog_url."';</script>");
else echo "<center><br><br><br><h1>Facebook Login failed</h1><br>Please refresh web page and try again.</center>";
exit;
function getdom()
{
return strtolower(str_replace("www.","",$_SERVER['SERVER_NAME']));
}
function getfbres($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
if(curl_error($ch)) $err=curl_error($ch); else $err="";
curl_close($ch);
//echo "<pre>info:<br>"; var_dump($info); echo "<br>output:<br>"; echo $output; if (strlen($err)>0) echo "<br>error:<br>$err"; echo "</pre><br>";
if ($output === false || $info['http_code'] != 200)
{
// $GLOBALS['err']=$output."\nhttp code:".$info['http_code']."\n".$err;
// echo "<pre>info:<br>"; var_dump($info); echo "<br>output:<br>"; echo $output; if (strlen($err)>0) echo "<br>error:<br>$err"; echo "</pre><br>";
// exit;
return false;
}
return $output;
}
?>
Event if the data cannot be retrieved (which should not be the case according to my tests using application access_token in older format APP_ID|APP_SECRET) you can easily save this details at your end linked to request id you get while sending it to user and later issue redirection based on data you already have.

Load PHP file with document.createElement()

How could I make this work? I want to load a php file like this:
Click button.
Call Javascript function.
In Javascript function create an img with src file.php.
This should force the loading of the php. Here is the code.
<script type="text/javascript">
var d;
function callSave() {
alert ('calling');
if (d) document.body.removeChild(d);
// d = document.createElement("script");
d = document.createElement("img");
d.src = "savepages.php";
//d.type = "text/javascript";
document.body.appendChild(d);
}
</script>
Then in savepages.php I do another alert to verify that the php is called and it isn't. Here is the savepages.php.
<?php
echo "alert('from the php');";
?>
The alert from the php doesn't happen. Is there a different element type that will force loading of the php? I don't have ajax installed, so I need a workaround like this.
Thanks.
You could use an iframe element
<script type="text/javascript">
var d;
function callSave() {
alert ('calling');
if (d) document.body.removeChild(d);
d = document.createElement("iframe");
d.src = "savepages.php";
document.body.appendChild(d);
}
</script>
Found out the better way to handle this. There is this simple code that explains how to call a javascript function from a form event and from that javascript function load a PHP file. The code found at http://daniel.lorch.cc/docs/ajax_simple/ is also given here:
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function validate(user) {
http.abort();
http.open("GET", "validate.php?name=" + user, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('msg').innerHTML = http.responseText;
}
}
http.send(null);
}
</script>
<h1>Please choose your username:</h1>
<form>
<input type="text" onkeyup="validate(this.value)" />
<div id="msg"></div>
</form>
validate.php
<?php
function validate($name) {
if($name == '') {
return '';
}
if(strlen($name) < 3) {
return "<span id=\"warn\">Username too short</span>\n";
}
switch($name) {
case 'bob':
case 'jim':
case 'joe':
case 'carol':
return "<span id=\"warn\">Username already taken</span>\n";
}
return "<span id=\"notice\">Username ok!</span>\n";
}
echo validate(trim($_REQUEST['name']));
?>