How do I remove special characters in URL codeigniter - php

How do I remove special characters in URL codeigniter. I really confuse why this codeigniter getting the "#" or other ('Special Characters) in href and putting it in URL.
for example:
Company
<a href='company'> Add company </a>
URL shows:
localhost/app/home/#company
Any help? thanks

Load your helper url. Like this $this->load->helper('url');
then use
url_title()
Takes a string as input and creates a human-friendly URL string. This
is useful if, for example, you have a blog in which you'd like to use
the title of your entries in the URL.
Example:
$title = "What's wrong with CSS?";
$url_title = url_title($title);
// Produces: Whats-wrong-with-CSS

# is called hash.
You click on 1 link, the hash adds to your url.
You click on 2 link, it tries to go to url#company, browser will recognize anything after # symbol as hash.
Try to avoid this by putting onClick() javascript event on button and returning false.

The change you need to make is in the company url.
Add company
The # in a url identifies a fragment within a document.

Related

Html extra attributes call as request

My Html links has extra attributes, like:
<a cat-data="175" rt-data="154" href="index.php?view=item"></a>
<a cat-data="775" rt-data="134" href="index.php?view=item"></a>
<a cat-data="575" rt-data="174" href="index.php?view=item"></a>
In this code is to see: cat-data="" and rt-data=""
If i click on this link and go to next page, can i request this data? cat-data="" and rt-data=""
Adding arbitrary attributes to an <a> element will not transfer them as part of the URL. So no, at least not as it stands.
You can encode them in the URL in the first place:
href="index.php?view=item&rt=174&cat=575"
and they will be accessible through $_GET.
You could also use JavaScript to modify the href attribute based on the other attributes, but that is needlessly complicated and dependant on JavaScript, so it is not recommended.
Note that adding arbitrary attributes to an element will make your HTML invalid and is not recommended. HTML 5 allows custom attributes if the name starts with data-, which might be what you are trying to use here, but you are using data as a suffix when it must be a prefix.
the data attribute uses for jquery and javascript and you can't have them in the next page, or on servers side, you can add the data to the url and then get them as get or post,
you can also store data on cookies and get the cookies on the next page
please use the next url : href="index.php?view=item&cat-data=175&rt-data=154

On clicking a button on a web page, can a dynamic link be generated? can we navigate webpage to the dynamically generated link

I am new to PHP and javascript programming
I have a string that can be "abc" or "aac" or "aaa" etc based on the inputs given by the user. After the user clicks some button(say submit) I want to generate a dynamic link like www.domain.com/abc or www.domain.com/aac based on string and navigate the user to the generated link. Is this possible?
Thank You
You can actually define a function and set it your form action. Then taking the user input it will be really each in the function to use header('location:YOUR_SITE_URL/'.$_GET['user_input']); die; for redirecting the user to desired url.
Hope that helps.
Yes it is possible, you can pass the string variable throw POST or GET when the user click submit
and then echo the link you want with the string congrenated. assuming you want to use php take a look at the example
$adress = "www.domain.com/";
$string = $_POST["get_string"];
$result = $adress + $string;
echo $result;
Possible, using routing. A real world example is how your usernames get to be part of the URL in social sites like Facebook.
What you need is a database of some sort to store the string, and it's matched data (could be an ID, or some identified) to tell the server what to load when that string is received. You'd also need routing code, which parses the entire url in search of that certain segment which should contain the string. This is how routing works in frameworks like CodeIgniter, Connect and Express.
In JS, routers in Connect look like:
app.route('/users/:username',function(username){
//okay! we got the username!
//now we'll look for it in the database if it's there
});
For PHP, here's an article regarding URL parsing.
In PHP :
Use methode in your page and store the variable to $UrlName (for example)
and continued with
echo("<script>location.href = \"www.domain.com/" . $UrlName . "\";</script>");
First in page1.html:
<form method="post" action="page2.php" >
String: <input type="text" name="string" />
<input type="submit" />
</form>
Then in page2.php:
header('location:www.domain.com/string/'.$_POST['string']);
But you should put a .htaccess containing:
Redirect /string/(.+) /page3.php?string=$1 [B,QSA]
And page4.php:
echo $_GET['string'];

Hide id from url

I want to pass an id from one page to another when user clicks a url. There can be multiple url each corresponding to a separate id. Based on url clicked, I want to pass corresponding id and an action. Currently I am using following approach:
<a href="Process.php?action=del&id='.$id.'">
However both action and id are visible in url. Is there any way to hide this information in url and not passing it through url?
Also if I pass them using hidden fields, they can be accessed using browser dev tools. I want to make them secure so they can't be read or modified at all.
I would like to hide this for security purpose so no any user can see this
In HTML only, you'll not able to pass "hidden" variables through $_GET.
If you really want to hide some variables when a user click on a link, you can use Javascript with an auto-submitted form to use $_POST variables.
Example
<form method="POST" action="yourpage.php" id="yourform" style="display:none;">
<input type="hidden" name="hiddenfield" value="__" />
</form>
<a href="" onclick="document.getElementById('yourform').submit();return false;" />
Now, in yourpage.php, you'll be able to obtain the $_POST['hiddenfield'] value.
Edit:
I don't think it can be possible to really hide the values from dev tools. Btw, you can maybe use sessions, it will be more "secure"..
Example:
// page1.php
session_start();
$_SESSION['yourname'] = 'yourvalue';
// page2.php
session_start();
$_SESSION['yourname']; // Contains 'yourvalue'
The best way to hide id(if you mean security) is to encrypt it. You should use MCRYPT function to encrypt the id. You can encrypt both ID and your ACTION in one string and just pass this string to URL and then when you want to use it you can decrypt parameter and split it. When you connect it with MOD_REWRITE in htaccess you can get url like:
<a href="Process,Some title of yourpage,í,eHGxC•z»#”“§``"> to make it more "pretty" you can use base64 on this string.
or with base64, mcrypt and mod_rewrite
<a href="Process,SWRlYW">
to decrypt string you should use base64_decode(), mcrypt_decrypt()
You can use base64 for this (if security is really a big concern). Before passing it to the URL,
you can encode it first and then in the receiving end, you can decode it.
Check this URL : http://www.webtoolkit.info/javascript-base64.html
EDIT:
Please ignore the line above in the bracket.
Based on the comments below, base64 is really not responsible for security. Better approach is to use a server sided language to encrypt/decrypt values. Using base64 through javascript is not a good idea. Thanks Bobby.

How to make a window pop up from a link using javascript

I am making a bookmarklet for my url shortener. What it does is it shortens the current url of a page when you click on the bookmarklet, so you don't have to go to a site to shorten a url, but what I need is for the bookmarklet to return a pop-up window with the shortened url listed below.
What I've done so far is this:
javascript:u=encodeURIComponent(location.href);s='http://n1x.co.uk/create.php?url='+u;window.open(s,'shortened','location=no,width=400,height=300');
If you have bookmarked this, you will notice when you click on it, it does shorten the url of the current page, but it also shows the url shortener webpage, and what I only need is plain text and a link to copy it.
Please help!
Edit: Sorry I'm that bad at php, but how can I make a parameter "responseType"? Thanks
What is shown in the popup is what is returned by http://n1x.co.uk/create.php. You will have to modify the php to return only the shortened url in plain text. If the php is being used by the shortener site also, what you can do is pass a parameter to create.php that tells it whether to return the whole page like it does now or to return only the plain text url. For example a parameter called 'responseType'. You can modify the create.php to say that when responseType = 'plainurl', return simply the shortened url and not the whole page.
javascript:u=encodeURIComponent(location.href);s='http://n1x.co.uk/create.php?url='+u + '&responseType=plainurl';window.open(s,'shortened','location=no,width=400,height=300');

Pass complex URL as parameter in PHP

I'm trying to pass a complex URL as a url parameter but the problem occurs if the url contains & for example I want to pass the following link as a parameter
http://www.google.ps/search?hl=en&client=firefox-a&hs=42F&rls=org.mozilla%3Aen-US%3Aofficial&q=The+type+%27Microsoft.Practices.ObjectBuilder.Locator%27+is+defined+in+an+assembly+that+is+not+referenced.+You+must+add+a+reference+to+assembly+&aq=f&aqi=&aql=&oq=
I'm trying to get a URL as a parameter from a user and redirect user to this URL.
How could I handle this in PHP?
The whole Story:
I'm trying to make some ads analytics on flash files so user submit flash ads to a website which contains a link to the required webpage.
Now,my client needs to know how many times this flash file was clicked.To solve this I 'll till every one who submits flash to write a link to my client webpage and pass the required URL as a parameter as follows
http://myclientwebpage.com/disp.php?link=www.google.com&id=16
by this way I can update my database and get a count for how many times this link was clicked
Use urlencode() or rawurlencode().
You wrote:
I'm trying to get a URL as a parameter
from a user and redirect user to this
URL.
But you didn't answer the question - how do you get that URL? How does user provide you with it? Is it written in <input type='text'/>? Or does user click some link that contains URL as one of parameters? Or is passed as ID of some URL that is stored in DB?
One case that comes into my mind - replacing URLs in plain text and sending user to some "redirecting page" before opening real page, so final page does not see HTTP referrer which might contain some secure data (e.g., session ID). In this case, you would write
<a href='redirect.php?link=<?php echo rawurlencode($url); ?>'>
<?php echo htmlspecialchars($url); ?>
</a>
instead of
<a href='redirect.php?link=<?php echo $url; ?>'>
<?php echo htmlspecialchars($url); ?>
</a>
From what I understand, you'll need to replace & into &.
$url = str_replace('&', '&', $url);
& is reserved, used for separating GET parameters, & is for writing a literal ampersand in a URL.

Categories