403 error on passing parameters - php

I have following function in a php file :
function bc_output($vars) {
switch($_GET['a']){
case 'addip':
bc_add_licenses($vars, trim($_GET['current_ip']));
break;
case 'addiprequest':
if(isset($_POST['submitaddip'])) {
display_guidance_text();
bc_add_licenses_request($vars, $_POST);
} else {
display_guidance_text();
bc_get_licenses($vars, '4');
}
break;
default:
display_guidance_text();
bc_get_licenses($vars);
break;
}
}
Now when i go to url such as http://website.com/addon.php?module=b&a=addip it works fine, although for second case i.e http://website.com/addon.php?module=b&a=addiprequest browser throws 403 error..
Can anyone guide me where to proceed from here, i have echoed etc in the function but always 403 error.
Please comment if you need more info.

Related

PHP error notices. Should they never be ignored?

I'm researching how to better organize my website content with PHP, and I had a question regarding unimportant error notices.
<?php
switch ($_GET['filename']) {
case 'home':
require('src/home.php');
break;
case 'quiz';
require('src/quiz.php');
break;
default:
if ($_GET['filename'] == '') {
include('src/home.php');
} else {
header('HTTP/1.0 404 Not Found');
include('src/page_not_found.php');
}
break;
}
?>
For example here; it's obviously telling me that it's getting undefined when I try to get the filename in the URL parameter. In this context, it's empty, and I'm doing this on purpose to check if there's something in there and if it should be interpreted as one of my other files.
I'm aware that you can add "error_reporting(E_ERROR | E_PARSE);" at the start of the line to hide the notice and the website will work just fine like that, but I was wondering if this is something I should always "fix"?
I was thinking of doing an if condition before the switch case:
if ($_GET['filename'] == ""){
include('src/home.php');
}
But that will throw me a notice as well, since what I am checking is undefined and will trigger the error notice regardless. What should I do?
Tim Lewis answered my question, thank you by the way!; Instead of hoping that a file is there, you can instead use isset().
So, instead of what I made, I would do something like this, to first check if the content is set before doing anything else:
<?php
if (!isset($_GET['filename'])){
include('src/home.php');
} else {
switch ($_GET['filename']) {
case 'home':
require('src/home.php');
break;
case 'quiz';
require('src/quiz.php');
break;
default:
header('HTTP/1.0 404 Not Found');
include('src/page_not_found.php');
break;
}
}
?>

can i call stripe library if i store it as a string in a variable?

i'd like to have a generic function for retrieving objects from stripe (customers, subscriptions, coupons, etc).
i'm maybe not going about it the correct way, but the function was getting quite long while handling errors for each type of retrieval- i was doing the try catch error handling sample provided by the stripe documentation over and over in the switch. so i'd like to only have one try catch statement, and have the try evaluate dynamically based on the object type i'm retrieving. is this possible? otherwise i can just go back to the very long function with all the try catch statements.
function stripe_retrieve_object($objectName,$objectId) {
switch ($objectName) {
case "coupon":
$retrieveStripeCode = "\Stripe\Coupon::retrieve(\"$objectId\");";
break;
case "customer":
$retrieveStripeCode = "\Stripe\Customer::retrieve(\"$objectId\");";
break;
case "subscription":
$retrieveStripeCode = "\Stripe\Subscription::retrieve(\"$objectId\");";
break;
default:
echo "There was a generic error. We were unable to retrieve payment data, and no updates to payment were made. Please contact admin#email.com";
} # switch ($objectName) {
try {
$stripeTry = eval($retrieveStripeCode);
return $stripeTry;
catch(\Stripe\Error\Card $e) { ... }
} # function stripe_retrieve_object($objectName,$objectId)
i see in the logs at stripe that the call is being made to retrieve the object, but the response body is empty on the stripe dashboard, and nothing returns from the $stripeTry = eval($retrieveStripeCode); i tried var_dump($stripeTry) and it came back NULL.
You can use variable functions instead of eval().
Note that PHP 7.x is required to use 'ClassName::methodName' as variable functions.
function stripe_retrieve_object($objectName,$objectId) {
$
switch ($objectName) {
case "coupon":
$retrieveStripeCode = '\Stripe\Coupon::retrieve';
break;
case "customer":
$retrieveStripeCode = '\Stripe\Customer::retrieve';
break;
case "subscription":
$retrieveStripeCode = '\Stripe\Subscription::retrieve';
break;
default:
echo "There was a generic error. We were unable to retrieve payment data, and no updates to payment were made. Please contact admin#email.com";
} # switch ($objectName) {
try {
$stripeTry = $retrieveStripeCode($objectId);
return $stripeTry;
catch(\Stripe\Error\Card $e) { ... }
}

Zend: 500 error instead of 404

Problem with 404 errors in Zend Framework 1. http://www.url.nl/path/wrong returns a 404 error (because the /path part exists). But when the first path is wrong (the root), it returns a 500 error. So http://url.nl/wrong returns a 500. Anybody who experienced the same issue? This is my error handler:
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found '.$role;
if (!$role) $this->_helper->layout->setLayout ( 'pages/404' );
else $this->_helper->layout->setLayout ( '404' );
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;
}
if ($errors->exception instanceof Zend_Acl_Exception) {
// send needed headers...
// prepare log message...
// render info: resource_not_found.phtml
$this->_helper->viewRenderer('error-no-access');
$this->_helper->layout->setLayout ( '403' );
}
EDIT:
The ACL manager was the problem, contained some problems in redirects etc. Most of the pages where redirected to the back-end and restricted because a normal user was trying to reach the page.
/*if (!$role) $this->_helper->layout->setLayout ( 'pages/404' );
else $this->_helper->layout->setLayout ( '404' );
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;*/
Try commenting the above section (like I did). This will tell you the actual problem at your file location(at your url). Once you know the problem, you can solve it as well.
Hope it helps.

Zend 301 Redirects - some mysteriously not working?

I have a problem whereby some redirects are not working and some are. I am using a crude way of doing a redirect, which is catching the url in the errorAction of the ErrorController and then having a few if statements and then doing the redirects as follows:
public function errorAction()
{
$request = basename($this->getRequest()->getRequestUri());
$this->getHelper('redirector')->setCode(301);
if ($request == 'rand.html')
$this->_redirect('/services/currency/rand');
if ($request == 'dollar.html')
$this->_redirect('/services/currency/dollar');
if ($request == 'zim-dollar-currency.html')
$this->_redirect('/services/currency/zim');
//About 20 of these If statements
$errors = $this->_getParam('error_handler');
//load appearance stuff
if (!$errors) {
$this->view->message = 'You have reached the error page';
return;
}
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$priority = Zend_Log::NOTICE;
$this->view->message = 'Page not found';
$this->view->headTitle()->prepend('Page Not Found');
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$priority = Zend_Log::CRIT;
$this->view->message = 'Application error';
$this->view->headTitle()->prepend('Application error');
break;
}
$this->view->request = $errors->request;
}
So, some will work and some won't, like: zim-dollar-currency...
Not sure why this is. I have even checked things like windows line endings etc. Nothing...
Try use switch construction with default action

php session variable problem when unset

i have made a function to set a session variable $_SESSION['flash'] in order to store a message between page
function setFlash($string,$type="info") {
switch ($type) {
case "warning":
$_SESSION['flashtype'] = "warning";
break;
case "error":
$_SESSION['flashtype'] = "error";
break;
case "info":
$_SESSION['flashtype'] = "info";
break;
default:
$_SESSION['flashtype'] = "info";
break;
}
$_SESSION['flash'] = $string;
}
and a function to print this message
function printFlash() {
echo $_SESSION['flash'];
unset($_SESSION['flash']);
}
i call this function at the top of every page (naturally after session_start)
the problem is that it doesn't print nothing, but if I comment " unset($_SESSION['flash']);" it prints the message in every page.
how can i solve?
Solved sorry my fault.
my page is something like this
include "func.inc.php"
session start
function editSomething {
that call setFlash()
}
include "template.php" (where printFlash() is called)
now i put printFlash directly in my page and works..bah strange...what's my mistake?
On every page this is what happened:
Make a session
Display flash
Delete flash
Create 'flash' with value
You have to move Create before display.
(it's also not very usefull because you do not transmit 'flash' (it's delete right after been created)

Categories