How is defined current url in zend (inside job of a framework) - zend-framework

Tell please what script uses zend framework for definition current URL? More exactly I interest what use ZEND for definition domain name: this $_SERVER['HTTP_HOST'] or this
$_SERVER['SERVER_NAME'] ? (or may be something other)?
P.S. ( I search in documentation but not found, (I do not know this framework), also I search in google, but also not found answer on my question? )

Try use: $this->getRequest()->getRequestUri() to get current of requested URI.
In the view script use: $this->url() to get current URL.
Or using via static integrated Zend Controller front via instance:
$uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
You can get a value of URI implementation via singleton to get a value of request() data:
$request = Zend_Controller_Front::getInstance()->getRequest();
$url = $request->getScheme() . '://' . $request->getHttpHost();
On the View use it as:
echo $this->serverUrl(true); # return with controller, action,...
You should avoid hardcode such as example (NOT TO USE!):
echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
instead of this example use as on a view:
$uri = $this->getRequest()->getHttpHost() . $this->view->url();
If you want using getRequest in ZEND more explore The Request Object.
SKIP IT BELOW (AUTOPSY EXAMPLE HOW WORKS IT).
Full of example code how getRequestUri() how it works and why is isRequest instead using $_SERVER is because on a platform specific is randomly get a data:
first if uri null, thand if requested from IIS set is as HTTP_X_REWRITE_URL. If not, check on IIS7 rewritten uri (include encoded uri). If not on IIS than REQUEST_URI will check scheme of HTTP_HOSTNAME, or if failed use as ORIG_PATH_INFO and grab a QUERY_STRING.
If is setted, grab a data automatically via string of returned object $this in a class.
If failed, than will be set a parsed string than set it.
if ($requestUri === null) {
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
isset($_SERVER['IIS_WasUrlRewritten'])
&& $_SERVER['IIS_WasUrlRewritten'] == '1'
&& isset($_SERVER['UNENCODED_URL'])
&& $_SERVER['UNENCODED_URL'] != ''
) {
$requestUri = $_SERVER['UNENCODED_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
// Http proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
$schemeAndHttpHost = $this->getScheme() . '://' . $this->getHttpHost();
if (strpos($requestUri, $schemeAndHttpHost) === 0) {
$requestUri = substr($requestUri, strlen($schemeAndHttpHost));
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
return $this;
}
} elseif (!is_string($requestUri)) {
return $this;
} else {
// Set GET items, if available
if (false !== ($pos = strpos($requestUri, '?'))) {
// Get key => value pairs and set $_GET
$query = substr($requestUri, $pos + 1);
parse_str($query, $vars);
$this->setQuery($vars);
}
}
$this->_requestUri = $requestUri;
return $this;

Related

to identify if there is a route zend framework 2

I have a url that redraw $ this->view->url($item['action']) this way but this variable can contain the route in the system or not, how can I do this check, check if this route exists in ZF2 ?
One option in my mind is to pass the navigation object to the view
In controller:
return [
'navigation' => $this->navigation,
];
In view:
if($this->navigation->findOneBy('route', $item['action'])) {
$url = $this->view->url($item['action']);
}
Another option would be to enclose the call in a try/catch. If the function throws an exception, the route does not exist
try {
$url = $this->view->url($item['action']);
} catch(Zend\Router\Exception\RuntimeException $e) {
$url = '';
}

How to send form data in slim framework v3 in PUT routing

I am very new in slim framework and i am using slim V3 i have done post route and it works fine but when i try to update record with put method it will works with Content-type = application/x-www-form-urlencoded and update my record with success
when i try to send file into slim api with POSTMAN Chrome Extension it will not sending file with form data request.
Here is my code
$app->put('/message/{message_id}', function ($request, $response, $args)
{
$imagePath = '';
$data = $request->getParsedBody();
$files = $request->getUploadedFiles();
$file = $files['file'];
if ($file->getError() == UPLOAD_ERR_OK ) {
$filename = $file->getClientFilename();
$file->moveTo('assets/images/'.$filename);
$imagePath = 'assets/images/'.$filename;
}
$message = Message::find($args['message_id']);
$message->body = $data['message'];
$message->user_id = $data['user_id'];
$message->image_url = $imagePath;
$message->save();
if ($message->id) {
return $response->withStatus(200)->withJson([
'message_id' => $message->id,
'message_uri' => '/message/'.$message->id,
]);
}else{
return $response->withStatus(400)->withJson(['message'=>'something went wrong!']);
}
});
When you want to upload a file with postman you need to remove or disable the Content-Type inside the header.

Perl catalyst controller redirect not working

I have looked over this code and I can not understand the weirdness it exhibits. For a lack of understanding all I know
$c->res->redirect('qbo/home');
is being ignored, in favor of the redirect in the following if else condition. In other words, I always end up at the OAuthentication website.
If I block comment out the else condition I end up where I want to go qbo/home
sub index :Path :Args(0) {
my ($self, $c) = #_;
# Check to see if we have QBO::OAuth object in our user's session
# Create new object in session if we don't already have one
if(!($c->session->{qbo})) {
$c->log->info('Creating QBO::OAuth, save in user session');
$c->session->{qbo} = QBO::OAuth->new(
consumer_key => 'qyprddKpLkOclitN3cJCJno1fV5NzcT',
consumer_secret => 'ahwpSghVOzA142qOepNHoujyuHQFDbEzeGbZjEs3sPIc',
);
}
# Now we set our object variable to the session old or new
my $qbo = $c->session->{qbo};
######### GOTO 'qbo/home' ##########
$c->res->redirect('qbo/home');
####################################
if($c->req->params->{oauth_token}) {
$c->log->info('Now Redirect to access_endpoint');
# Get realmId and save it to our QBO::OAuth object in user session
$qbo->realmId($c->req->params->{realmId});
# Call QBO::OAuth->request_access_token
my $r = $qbo->request_access_token($c->req->params->{oauth_verifier});
$c->res->redirect('qbo/home');
} else {
my $callback = 'http://www.example.com/qbo';
# Request a token
my $r = $qbo->request_token($callback);
if($qbo->has_token) {
#Continue on down, Redirect to auth_user_endpoint
$c->res->redirect($qbo->auth_user_endpoint . '?oauth_token=' . $qbo->token);
}
}
}
Seems I am missing some basic fundamental about how this works. Any clues appreciated
From the fine manual...
This is a convenience method that sets the Location header to the redirect destination, and then sets the response status. You will want to return or $c->detach() to interrupt the normal processing flow if you want the redirect to occur straight away.
Note also the warning on that manual page about redirecting to a relative URL - you shouldn't do it. For your use-case, I'd recommend getting into the habit of using:
return $c->res->redirect($c->uri_for('qbo/home'));
or
$c->res->redirect($c->uri_for('qbo/home')) && $c->detach();
depending on your preference.

Magento admin url - remove index.php (Godaddy Server)

Magento installed on WAMP and working fine.
SITE URL = localhost/shop <-||->
ADMIN URL = localhost/shop/index.php/admin
I moved this magento to Godaddy server. It is NOT in the root folder. The site is in a sub folder named “shop”
SITE URL = mydomain.com/shop <-||->
ADMIN URL = mydomain.com/shop/index.php/admin
Front-end url is working fine - mydomain.com/shop/customer/account/login/
Admin url is not working with “index.php” included. When I remove “index.php” and call the url manually then it is working.
I want my admin url as http://mydomain.com/shop/admin/system_config/edit/....
MY CONFIGURATION
Use Web Server Rewrites = Yes
IN .HTACCESS
RewriteBase /shop/
How can I solve this?
An alternative solution can be found here:
How to remove index.php from admin URL
To remove the index.php from Magento admin URL add the following code on the top of the /shop/index.php file in Magento folder:
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$curUrl = curPageURL();
$pos = strpos($curUrl, "index.php");
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
//echo "The string '$findme' was not found in the string '$mystring'";
} else {
//echo "The string '$findme' was found in the string '$mystring'";
//echo " and exists at position $pos";
$newUrl = str_replace("index.php/", "", $curUrl);
header("Location: $newUrl");
exit;
}
?>
Enjoy :)

Zend_OpenId with Codeigniter

I am using the OpenId library from Zend with CodeIgniter and everything is working just fine except for the verify function.
$status = "";
if (isset($_POST['openid_action']) &&
$_POST['openid_action'] == "login" &&
!empty($_POST['openid_identifier'])) {
$consumer = new Zend_OpenId_Consumer();
if (!$consumer->login($_POST['openid_identifier'])) {
$status = "OpenID login failed.";
}
} else if (isset($_GET['openid_mode'])) {
if ($_GET['openid_mode'] == "id_res") {
$consumer = new Zend_OpenId_Consumer();
if ($consumer->verify($_GET, $id)) {
$status = "VALID " . htmlspecialchars($id);
} else {
$status = "INVALID " . htmlspecialchars($id);
}
} else if ($_GET['openid_mode'] == "cancel") {
$status = "CANCELLED";
}
}
The Openid library needs a Zend session to start so I also included that library. I am able to: enter openid, get redirected to 'openid-provider', validate there, and get redirected back.
However, I am not able to retrieve the 'openid_mode', so I'm not able to 'verify' the info. I don't understand what I'm doing wrong. Is it purely that this library will not work with CI without some heavy hacking?
Have you tried CodeIgniter’s OpenID library?
Zend's OpenId system is flawed in many ways (it doesn't work with Google, Yahoo etc). I think you'll be better off with this library instead: http://www.janrain.com/openid-enabled