Zend Framework, FusionCharts, PHP, Javascript - php

Kind of a weird one here: I have a Zend Framework setup in 1.12. My models are working fine and all of my includes are set...but in the view Zend can't seem to find a FusionCharts.js file that is there. I have it appended in the action as follows and when I check the path on Firebug it is absolutely correct- but still returns an error and claims that it can't find the .js file. Anyways- here's the code:
public function indexAction()
{
try{
$model = new Application_Model_DbTable_Daily;
$dau = $model->getStats();
$this->view->dau = $dau;
}
catch(Exception $e) {
$this->view->dau = $e;
}
$this->view->headScript()->appendFile('/dashboard/public/fusioncharts/Charts/FusionCharts.js');
}
So- in my view I get:
<?php
echo $this->headScript();
echo "<pre>";
$FC = new FusionCharts("Line", "500", "300");
$FC->setSwfPath("/public/fusioncharts/Charts/");
$strParamDAU = "caption=Daily Active Users;streamlinedData=0;decimals=0;decimalPrecision=0;formatNumberScale=0;slantLabels=1;labelDisplay=ROTATE";
$FC->setChartParams($strParamDAU);
foreach($this->dau as $k=>$v) {
$FC->addChartData($v['session_date'], "label=" . $v['DAU']);
}
$FC->renderChart();
echo "";
But when I look at the view in firebug I get an error saying that it can't find FusionCharts.js in the public directory (the path is definitely right!). Any ideas why this would be happening? It's there. The Firebug reads the right directory (GET localhost/dashboard/public/fusioncharts/Charts/FusionCharts.js) but the firebug error is saying that it can't see the file. Thanks for the help!!

If the file is realy there, and the Name is FusionCharts.js:
Try to add the BaseUrl (just to be on the safe side):
$this->view
->headScript()
->appendFile($this->view->baseUrl() . '/dashboard/public/fusioncharts/Charts/FusionCharts.js');
Next check your .htaccess, maybe you arent forwarding JS Files? Correct .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Related

htaccess call php script then continue processing

I have this specific problem where I have to check URL if its part is 8 chars long hash code that is saved in my database or its just normal URL where you want to navigate.
For example if i write url :
- www.example.com/A4s8Gga3
i want to process it with my script in php file
And if i write url :
-www.example.com/my-books
-www.example.com/about
i want to navigate on those pages.
I know i have to use htaccess (so much I managed myself) and so far it looks like this :
#part1
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (\/\w+)$ [NC]
RewriteRule ^(.*)$ mobile_redirect.php [L]
#part2
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
My mobile_redirect.php looks like this:
ob_start();
require_once('connect.php');
$request = $_SERVER['REQUEST_URI'];
$request_hotovy = str_replace('/', '', $request);
$request_hotovy = mysql_real_escape_string($request_hotovy);
$select = "SELECT HASH_ID,OFFER FROM kasko_send_form WHERE MOBILE_HASH_ID = '".$request_hotovy."'";
$query = mysql_query($select);
if(mysql_num_rows($query) > 0){
// request is mobile hash id
$result = mysql_fetch_array($query);
$hash_id = $result['HASH_ID'];
header("Location: some_link?def=".$hash_id);
} else {
// request is normal url
header("Location: ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
I know that it will end up redirecting in loop. I tried to put part1 after part2 and still have the same problem. I am using joomla and it have many urls (which im not able to write down) that are not real directories or files that is why i cant just use in my php file this solution :
ob_start();
require_once('connect.php');
$request = $_SERVER['REQUEST_URI'];
$request_hotovy = str_replace('/', '', $request);
$request_hotovy = mysql_real_escape_string($request_hotovy);
$select = "SELECT HASH_ID,OFFER FROM kasko_send_form WHERE MOBILE_HASH_ID = '".$request_hotovy."'";
$query = mysql_query($select);
if(mysql_num_rows($query) > 0){
// request is mobile hash id
$result = mysql_fetch_array($query);
$hash_id = $result['HASH_ID'];
header("Location: some_link?def=".$hash_id);
} else {
// request is normal url
header("Location: page_not_found.php");
}
Because there is clearly more url processing done in joomla after it ends reading my htaccess (i dont know much about joomla either).
Can you guys give me a hint how to process the url (then maybe alter it so it wont end up in loop and then alter it again after the part1 back to normal so it can continue processing as it would normally)?
Also if you guys have any good tutorials where I could learn such things it would be really helpfull, because i understand only basics of regex and how htaccess works ...
If you use Joomla for most of your URLs exact the one that should have this eight character string there is a simple solution for this.
Just use the regular Joomla .htaccess file and add two lines before RewriteBase /
RewriteCond %{REQUEST_URI} ^/[A-Za-z0-9]{8}$
RewriteRule .* mobile_redirect.php [L]
But the Problem here is that if you have regular URLs in Joomla with 8 character than they would be redirected es well e.g. http://example.com/lastnews
So for this URL's you have to add a exception, and the hole thing would lock like this:
RewriteCond %{REQUEST_URI} !^/latesnews$ [NC]
RewriteCond %{REQUEST_URI} !^/youandme$ [NC]
RewriteCond %{REQUEST_URI} ^/[A-Za-z0-9]{8}$
RewriteRule .* mobile_redirectt.php [L]
There is no way to redirect back to Joomla with the same URL if your script do not find a record in your DB. Either your script is handling the URL or Joomla dose it. So you have to provide a 404, or find a way to include the index.php file from Joomla in your script.

Pretty URL Conditional Rewrite

Our site allows for a pretty url 'etest.me/1234' where '1234' is a client id. As you can see below it redirects to our route.php file where we do our redirect. The problem is when a client uses 'etest.me' without the '/1234' they get the apache 'The requested URL /go/ was not found on this server.' message. I would like the url to go to another page when the '/1234' is missing.
Note that we have the domain and path forwarded to the non-existing '/go' directory so the rules below will catch it. The following is in our .htaccess file in the root directory.
RewriteEngine On
#restrict rewriting URLs ONLY to paths that DO NOT exist
RewriteCond %{SCRIPT_FILENAME} !-d
# commented out to speed up looking since we are not processig file names anyway
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^go/([a-zA-Z0-9/]+)$ ./route\.php?go=$1
Working perfectly fine for me. Hope this will work for you as well.
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^go/([a-zA-Z0-9]+)$ /route.php?go=$1 //when client id exist
RewriteRule ^([a-zA-Z0-9]+)$ /index.php // when no client id
You can add a new rule to handle this situation:
RewriteRule ^go/$ ./another_script\.php
I accepted the answer by Sahil and posted the entire logic below for others to use:
Domain: etest.me
Pretty URL: etest.me/1234 (where '1234' is a client id)
Forwarded to: etesting.io/go (with forward path option selected so the '/1234' will be include in the forward)
Note: There is no '/go' directory on the server, '/go' is used to trigger the redirect.
Wanted 'etest.me' (without client id) to go to index file in root directory.
Here is the rewrite rules in .htaccess:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^go/([a-zA-Z0-9/]*)$ ./route\.php?go=$1
Here is the route.php code:
<?php
if($_GET['go']){
$a = explode('/', $_GET['go']);
$c = count($a);
if($c == 1 || $c == 2){
header('location: ../../index.php?aid=' . $a[0] . '&tid=' . $a[1]);
exit;
}
else{
die('Invalid URL');
}
}
else{
header('location: ../index.php');
exit;
}
And finally the index.php file:
if($_GET['aid'] && $_GET['tid']){
header('location: test/register.php?aid=' . $_GET['aid'] . '&tid=' . $_GET['tid']);
exit;
}
elseif($_GET['aid']){
header('location: test/index.php?aid=' . $_GET['aid']);
exit;
}
else{
header('location: account/index.php?' . $_SERVER['QUERY_STRING']);
exit;
}
Hope this helps somebody in the future.
I would like a more elegant solution but it's behind me for now...

Php mvc -link redirection issue

I have developed a web application using php (custom MVC). The web app works fine on the localhost but not on godaddy server.
I have written redirect function as following:
public function redirect($controllerName, $action, $params=null) {
if($controllerName){
$link = Constant::$APP_URL . "/" . $controllerName. "/" . $action; }else{ $link = Constant::$APP_URL . "/" . $action; }
if($params != null) {
$link .= "?" . http_build_query($params);
}
header("Location:" . $link);
exit;
}
Take the following example:
The following on local server works, when I try to login:
https://localhost/project/login
If I type the same on my server, it does not work & redirects me to the following link:
https://example.com/login/login
"login" is a function in one of the controllers.
Any ideas?
My .htaccess file looks like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]
hey could you please provide us with the error report from cpanel. if you go into your cpanel on godaddy then go to error log it should show a report at the specific time of action. like when the button pushed. if you have javascript as well and nothing shows up(which i doubt) also check google by right clicking and going inspect element. this will give more info for what is actually going on. from there we could source a solution or you might even be able to google possible solutions before you need to ask.

123-reg.co.uk website and apache mod_rewrite

Hi this is my first time asking a question on here so go a little easy on me if my question is not clear or my code is not right lol. I currently uploaded my new php mvc website to 123-reg.co.uk and im using apache mod_rewrite with a router class. It works perfectly when im on my localhost but when its live, the mod_rewrite is ignored and the controller is not recognised e.g if i type http://www.examplewebsite.co.uk the home controller loads like it should but if i try to load a different controller e.g http://www.examplewebsite.co.uk/images it takes me too a server error 404 page. I have been trying to fix this for several days now with no success, i have done some research and 123-reg.co.uk does support mod_rewrite, i feel like im loosing it haha, any help would be greatly appreciated, Thanks in advance.
This is the router class:
class Router {
public function __construct()
{
if(empty($_GET['url']))
{
Help::loadApplication('controllers','home');
return new Home();
}
elseif(isset($_GET['url']))
{
$url = $_GET['url'];
$url = rtrim($url,'/');
$url = filter_var($url,FILTER_SANITIZE_URL,true);
$url = explode('/',$url);
Help::loadApplication('controllers',$url[0]);
if(class_exists($url[0]))
{
$controller = new $url[0];
if(isset($url[1]))
{
$methodName = $url[1];
if(method_exists($controller, $methodName))
{
$methodParams = (isset($url[2]) ? $url[2] : false);
$controller->{$methodName}($methodParams);
}
}
}
else
{
Help::loadApplication('controllers','home');
return new Home();
}
}
}
This is the mod_rewrite:
RewriteEngine On
RewriteBase /http://www.examplewebsite.co.uk
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/?url=$1 [QSA,L]
UPDATE !!
Anyone else that has this same issue, the reason it wasn't working is because 123-reg.co.uk don't support mod_rewrite on their Windows package but do on there Linux package, it would have been good for them to state that when I signed up for the Windows package but making the switch over to the Linux package now. Thanks for the help guys!
This is worth trying; Add this as your first line above RewriteEngine On
Options +FollowSymlinks
source: http://forum.modrewrite.com/viewtopic.php?f=4&t=2222
and I'm not so sure about your RewriteBase, maybe it should be
RewriteBase /
instead of having the full url?

redirect with header function not working

I have this htaccess filecontent:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^admin/([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/admin/index.php?page=$1&query=$2 [L]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/index.php?page=$1&query=$2 [L]
And now im trying to make a redirection depending on a session, very simple stuff. I have a Controller with this function:
protected function redirect($url) {
header("Location: http://localhost:8888/myproject/" . $url, true);
exit();
}
The ClientController that extends Controller has the page function
private function user_page() {
$this->redirect("homepage"); //Not working...
}
I have tried different ways of writing the location path like
Location: localhost:8888/myproject/" . $url,
Location: /myproject/" . $url,
Now after reading all posts on stackoverflow, I see none of these solutions have worked for me..
Edit: the solution to this can be seen on header redirect to Location does not work
After getting an answer from header redirect to Location does not work I found that the problem was some row of spaces that had been inputted after ?> in the Controller, so it took a while to notice it.
Clarification:
If you have the same problem make sure you have line numbers set and see if you can see any line numbers after the file content. If there is you may have blank lines after aswell. Just delete these. Needless to say, the same goes for linenumbers before filecontent

Categories