0

Is it possible to hide the URL link that I use in php in order not to show to user to prevent user to change the URL link? And I'm using get function on another php page to retrieve the package ID.

Example I have a php URL code like this:

<a href="banner.php?packageID=1234" >

When user click on the link and lead to the URL, is that possible to hide the "1234" and just show banner.php?packageID= on the URL link only?

Please guide me through this. Thanks

1
  • Why not use server side URL rewriting, like Apache's .htaccess with mod_rewrite, or NGINX with a proxy rewrite, so you can link to banner/1234, and have your server, internally, rewrite it to banner.php?packageID=1234? Commented Jun 12, 2015 at 5:05

6 Answers 6

1

No, it isn't possible. However, you can use rewrite rules to change the request URL such that it looks something like: banner.php/1234

A different approach would be to use a post request with a form, like so:

<form method="post" action="banner.php">
<input type="hidden" name="packageID" value="1234">
<button type="submit">Go</button>
</form>

In this case, only the button is visible. The button can be styled like a link,

Sign up to request clarification or add additional context in comments.

Comments

0

You can do this using .htaccess file, add following code

Your .htaccess file

options -multiviews
<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteBase /
RewriteRule ^banner/([^/.]+)?$ banner.php?packageID=$1&%{QUERY_STRING}

In PHP

<a href="banner/1234" >

Comments

0

in simple words it is not possible to hide that value from URL at all. Below are other approaches for you:

Approach 1

Use better URL like banner/1234

Approach 2

User title value instead of Id like banner/banner-title, I would suggest this.

Comments

0

You can pass the packageID in an encrypted format so that the user can't guess it or alter it.

Comments

0

I have checked the your problem.Its not possible to hide a specific attribute from the html tag using CSS. You can see the below post also: How to hide href attribute of <A> tag via css when using window.print

Another options as above you can use packageID in encrypted format or url rewriting.

One more option, you can try it with javascript or jquery like below:

<a href="http://example.com/banner.php?packageID=" rel="1234" id="testurl" >testing</a>

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#testurl").click(function(){
        var rel = jQuery(this).attr('rel');
        var href = jQuery(this).attr('href');
        window.location = href+rel;
        return false;
    });
}); 
</script> 

Comments

0

You also can use this:

<a href="javascript:;" onclick="window.location='banner.php?packageID=1234'" >

or

<a href="banner.php?packageID=" onclick="window.location='banner.php?packageID=1234';return false;" >

But I don't think is the best way to hide URL,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.