how to remove the # in my url [duplicate] - php

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 6 years ago.
https://progressive.e-inkasso.dk/login#application/views/ajax/dashboard.php
when my webpage loads there is this # and not a / i tried to route it to be only dashboard or login in the route.php file but there was no way so far that it worked.
$route['default_controller'] = "Register";
$route['404_override'] = '';
$route['login/(:any)/(:any)/(:any)/(:any)/(:any)'] = "Register/login";
$route['(:any)/dashboard'] = "Register/index/$1";
//$route['(.*)/login'] = "Register/login/$1";
$route['(.*)/register'] = "Register/register/$1";
and i have no clue how to fix it

I think it has something to do with AngularJS and its routing integrated in your website. This is not default behaviour of CodeIgniter. I inspected your page's source code and it seems to load some Angular Javascript things.
Didnt bother to munch to find what and where exactly. But my best guess is that AngularJS is doing this. You should probably redefine your question but i doubt it is possible to remove the trailing #. Good luck

Related

CodeIgniter URI routing with "#" as path parameter [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 2 years ago.
I have a Home.php controller and terms method in it. I have a url like this: https://www.example.com/terms and it works fine.
My routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['terms'] = 'home/terms';
Now, I need to change the url to be like this: https://www.example.com/#/terms Notice the "#" in-between.
I tried adding this to routes but it didn't work:
$route['#/terms'] = 'home/terms';
The above change show home page when I open https://www.example.com/#/terms
However, if I put any other permitted character $config['permitted_uri_chars'] mentioned in conifg.php in place of # then it works fine:
$route['a/terms'] = 'home/terms'; // this works: https://www.example.com/a/terms
$route['2/terms'] = 'home/terms'; //this works: https://www.example.com/2/terms
I also added # in $config['permitted_uri_chars'] but that too didn't work. Keeps showing home page only.
Also, can anyone explain me why # is not treated the same way as other characters in permitted_uri_chars?
Controller is Home.php and method is terms(). Using CodeIgniter version 3.1.11
Thank You!
EDIT:
I need to know if I can achieve it using Codeigniter's routing? Or maybe some rewrite rule using .htaccess?
This is caused by the web browser, not CodeIgniter. Web browsers treat # and anything after it in a URL to be a reference to an element on the web page pointed by the URL before the # part.
So for a URL https://example.com/#page1, the web browser will make a request to https://example.com/ and then look for an element with ID page1 on the web page.
If you want different pages to load by using a '#' in your URLs, it's done using front-end frameworks like Angular. Check Angular's routing features to understand how it makes the browser load a different view for different URI paths after #.

Is it possible to use a PHP function inside of an HTML file? [duplicate]

This question already has answers here:
How do I add PHP code/file to HTML(.html) files?
(12 answers)
Closed 3 years ago.
I am working on an internet programming project and this is my first assignment in PHP. I read that you cannot put PHP code inside of HTML but my professor has these instructions which contradicts that.
Can someone please interpret what he might mean? Thank you in advance!
You can certainly use HTML in PHP if your server is set up for it.
echo '<div>' $message . 'was the value entered. </div>'
In order to run PHP inside .html files you need to send header request for the app to be able to recognize the markup. Otherwise PHP wont run.
To do this you need to create a .htaccess file in your root web directory and add this line to it:
AddType application/x-httpd-php .htm .html
Or you can use this simple rule in your .htaccess :
RewriteRule ^([^.]+)\.html$ $1.php [L]
On a side note, using PHP inside .html files is very unnatural. It is preferred to use extension .php that's what it is meant for. You can naturally use HTML inside PHP. My interpretation from your assignment is that your teacher is asking you to use HTML inside PHP and not the other way around.
You want to use an if statement to check whether a variable is empty or not :
if($message !='' || $message !=null){
echo $message;
}else{
echo 'Variable is empty';
}
Have a look at the php documentation for more PHP statements, what they are and how to use them :
https://www.php.net/manual/en/language.control-structures.php

Is it possible to get URL slash/ parameters with simple php?

is it possible to get parameters like:
index.php/bar/foo with php?
I know that I can use s.th. like index.php?a=bar&b=foo and the user $_GET['a']. But I need to do it with the other way.
The answers here just look like guesses. mod_rewrite presumes apache webserver (we don't know which one you use) and is way too much for this simple task.
Apache's default behaviour is to map index.php/xx/xx to index.php?xx/xx.
Look how easy this is:
$args = explode('/', $_SERVER['QUERY_STRING']);
print_r($args);
EDIT: As DanFromGermany pointed out it is actually possible to have urls like index.php/bar/foo without using mod_rewrite or such. I guess the key here is to have a filename (index.php) in the url.
This has to be done in the web server.
In apache there is a module called mod_rewrite which can rewrite urls like index.php/bar/foo to another format such as index.php?a=bar&b=foo.
Examples, and a description of the topic: http://www.seochat.com/c/a/search-engine-optimization-help/creating-search-engine-friendly-urls-with-php/
What web server are you using?
I used following code to access slash parameters:
$args = $_SERVER["REQUEST_URI"];
$arg_arr = explode("/",$args);
print_r($arg_arr);
Hope this helps someone
To achieve the same either you work on httpd.conf for rewriting the URL or use PHP framework like codeigniter etc. which provide inbuilt functionality.

Codeigniter Remove .php and route to index.php [duplicate]

This question already has answers here:
How to remove "index.php" in codeigniter's path
(27 answers)
Closed 9 years ago.
If a user follows this url:
http://localhost/events/info.php
How can I remove the .php extension via htaccess so the user gets routed to index.php and my Events Controller into the Info function? I basically want to create 301 redirects.
http://localhost/events/info
I have old indexed links that I need to redirect to my controller functions so I do not get 404s.
use
RewriteEngine On
RewriteRule ^events/info/$ index.php [L,QSA]
What version of CI you are using?
normally we already got like this without .php
http://localhost/events/info
To route to index.php (in view folder): you only need to do like this in your controller file.
controllers/events.php
function info(){
redirect('events/index');
}
function index()
{
$this->load->view('index.php');
}
A 301 redirect can be achieved using .htaccess
Redirect 301 events/info.php http://localhost/events/info
You may find this tool useful for generating the redirects.
If you just want to route the URL: http://localhost/events/info.php to the info function in your events controller, then you don't have to remove .php from the URL, you can add a route in application/config/routes.php.
$route['events/info.php'] = 'events/info';
If you haven't already then you must also remove index.php, CodeIgniter's user guide explains how to do this.
If you'd like to remove .php from all your URLs to make them look cleaner, then there a lots of resources available, including other answers on SO.

parameters as part of url instead of after question mark [duplicate]

This question already has answers here:
How to create friendly URL in php?
(8 answers)
Closed 6 years ago.
I want to know if we can achieve something like this:
example.com/apps?id='blahblah' converted to example.com/apps/id/blahblah ie. parameters becoming pages themselves. I want to create seperate urls for each id but dynamically. Is this possible in php or any other workaround.
You need to use .htaccess to achieve this.
.htaccess basically rewrites the url to your original location. So to do what you asked in your question it would be like this:
RewriteEngine on
RewriteRule apps/id/(.*?)$ apps?id=$1
You're probably getting downvoted because "mod rewrite in php" has been widely documented with tutorials and articles. Try to search for it here or on Google and you will find plenty of results.
Anyway, if you can't or won't use Apache's mod_rewrite, you can do the same in pure PHP by parsing the HTTP request and process accordingly.
For example
$request_path = $_SERVER['PATH_INFO'];
$request_path = explode("/", $request_path);
// example.com/apps.php/id/blahblah
// $request_path[0] => "example.com"
// $request_path[1] => "apps.php"
// $request_path[2] => "id"
// $request_path[3] => "blahblah"
Notice I added .php extension to apps. If you wish to hide the .php extension you must use mod_rewrite anyway.
From here on you can use the $request_path to figure out what the request wants.

Categories