How to hide the $_GET parameters using htacess? [duplicate] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
It is possible to hide get value from url (rozgaarexpress.com/profile.php?id=22) using .Htaccess.I want to hide ?id=22.
Then URL Looks like rozgaarexpress.com/profile.php
My first page demo.php
I am just passing this url
HTACCESS
second page profile.php
<?php
$id=$_GET['id'];
echo $id;
?>

You can't hide the ID parameter, even if you use .htaccess to achieve that. I mean you can do it but you will be able to use a single ID when accessing profile.php page which I don't think is the case you want.
You can do it by using sessions like:
demo.php
session_start();
$_SESSION['id'] = 22;
echo 'My profile';
profile.php
session_start();
echo $_SESSION['id'];

im sure you asked this question to find a way to avoiding show ID to public.
you can use session in this case like this:
<?php
session_start();
$_SESSION['session_name']=$id; // Set the value of the id you want to pass.
?>
and in profile.php page you need this:
<?php
session_start();
$id = $_SESSION['session_name'];
?>
or you can use JQuery.post to pass your data.

I would rather take the desired profile ID from the Client. This allows the end-user the option to open two different profiles from the same page:
<script type="text/javascript">
function setInputAndSubmit(input) {
var form=document.getElementById("skfrom");
var inputEl=document.getElementById("LANG");
inputEl.value = input;
form.submit();
} </script>
<form id="skfrom" name="myform" action="http://rozgaarexpress.com/profile.php" method="POST">
<div align="center">
First ID
<br>
Another ID
<br><br>
Same ID
<br><br>
You can even receive input from users and send it together with the ID.
<input type="text" size="25" value="Some other field you want visible">
<input type="hidden" id="LANG" name="Language" value="English">
</div>
</form>

Related

How to send 2 variables to a second PHP page using get [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I had some help yesterday on passing a variable to a PHP page (Thanks). I now am stuck again.
Scenario - I am new so I know there is an easier way but at the moment I have a database that I want to query. Page 0 - I select a place (Called 'categorynum' [ I then pass that to page 1 (Which is the code below where it pulls in the categorynum from previous page and allows me to select a date. I now want to pass that date (categoryevent) and place (categorynum) to page 2. The below code passes categoryevent no problem but what am I doing wrong as its only passing the text of categorynum over.
CODE for page 1
<form method="get" action="page2.php">
<p>Date of Investigation:</p>
<select name="categoryevent">
<?php
foreach ($catByDate as $num=> $event){
print "<option value=\"$event\">$event</option>\n";
}
?>
</select>
<input type="hidden" name='categorynum' value='$categorynum'>
<input type="submit" value="Show Summary">
</form>
Ahh now I see it. You are not actually loading the value of $categorynum into the hidden input.
So change how you set the value into the input element
<input type="hidden" name='categorynum' value='<?php echo $categorynum; ?>'>

After deleting rows on multiple selection of checkbox not getting values of $_GET? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i'm deleting products(data) on checkbox and after click on delete button i'm deleting rows but the problem is after delete is complete i'm not getting $_GET global array variable values back to my page which is essential to load page...
$_GET['cid'] is category id and $_GET['scid'] is subcategory id...just because of missing values my page is showing up without data
if(isset($_GET['delete']))
{
$cnt=array();
$cnt=count($_GET['chkbox']);
for($i=0;$i<$cnt;$i++)
{
$del_id=$_GET['chkbox'][$i];
$query="delete from products where product_id=".$del_id;
mysqli_query($con,$query);
header("Location:topics.php?cid=".$_GET['cid']."&scid=".$_GET['scid']."");}}
on header location i'm not getting value ,
plz ignore if u found any mistake in my questioning because this is my first question
Given the information provided, I'm going to assume that this is the problem and hopefully this can be helpful...
Presumably you have a form of some kind which you access via your URL: localhost/php/FORM%20LOGIN/topics.php?cid=1&scid=5
<form method="GET">
// some form elements
<input type="submit" name="delete" value="Delete" />
</form>
Something at least similar to that. Then when you click the delete button you send a request to a URL which is more like: localhost/php/FORM%20LOGIN/topics.php?delete=Delete&...
So your original cid and scid values are lost. This is because they weren't included in the form. But since you had those values when the page loaded, you can include them in your form. Something like this:
<form method="GET">
<input type="hidden" name="cid" value="<?php echo $_GET['cid']; ?>" />
<input type="hidden" name="scid" value="<?php echo $_GET['scid']; ?>" />
// some form elements
<input type="submit" name="delete" value="Delete" />
</form>
By including the values in your form, they will be included in the form's request to the server.

How to implement "Remember me" [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Sorry I am asking a question that has been asked before but in spite of reading all of them, I am still confused what to do.
What exactly I have to do to implement the remember me feature in my website I am building as my final year project. Is calling the function "setcookie()" alone sufficient?
setCookie() is all you need.
You can use it like this:
$cookie_value = 'MyUsername';
$cookie_expire = time() + 60*60*24*365;// 365 days
$cookie_path = '/';
setcookie('remember_me',$cookie_value, $cookie_expire, $cookie_path);
On the next pageload, you can fetch the remember_me cookie value with:
$_COOKIE['remember_me'];
But the 'next pageload' part is important because PHP cookies cannot be set and also read in the same browser action.
In the most simple way possible. The way I would bring this all together for demonstration for your project is have a php page with an html <form> that posts to itself.
Your filename would be something like my_form.php
inside it would be:
<?php
// If we received a username from the form, remember it for a year.
if( $_POST['username'] ):
setcookie('remember_me',$_POST['username'], time()+60*60*24*365, '/');
endif;
?>
<?php
// Display a message if the user is remembered.
if( isset($_COOKIE['remember_me']) ):
echo '<h2>Welcome back, '.$_COOKIE['remember_me'].'!</h2>';
endif;
?>
<form action="" method="post">
<input name="username" type="text" placeholder="Your Username" value="<?php echo $_COOKIE['remember_me'] ?>" required />
<button type="submit">Remember me</button>
</form>
This form submits to itself. If you see the username you just entered in the welcome message, then it is remembering you.
Very important! The setcookie() call in PHP must be the first thing in your my_form.php file. Otherwise setcookie() will not work if any output has happened to the web-browser before you call the setcookie() function.

Php simple input to array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Recently I started with PHP and there's something im trying to find out.
This is what I want:
Input field + Submit.
When u submit the form, the value of the input field goes in an array. lets say $array = array();
Every time you submit the value gets put in that array.
I've done things with $_GET and $_POST and other things like $_SESSION but I just can't get this to work..
Help would be appreciated! thanks!
EDIT: The information (list) will just be showed on the page. Not send to a mysql database or anything. When u refresh the page it would be gone.
It sounds like you want to keep the data that you submitted.
index.php
<?php
session_start();
if(isset($_POST['a_value']))
{
if(!isset($_SESSION['a_value']) || !is_array($_SESSION['a_value']))
{
$_SESSION['a_value'] = array();
}
array_push($_SESSION['a_value'], $_POST['a_value']);
}
?>
<form action="index.php" method="POST">
<input type="text" name="a_value">
<input type="submit" value="Go">
</form>
<?php
if(isset($_SESSION['a_value']))
{
echo '<br><br>Values so far:<br><pre>'.print_r($_SESSION['a_value'], true).'</pre>';
}
?>
there some better way for do this, but you can use the session like this:
you need 2 session variable for this aim, first for counting the array index, and second for value...
here is an example
<form method="post" name="frm" action="#">
<input type="text" name="txt" id="txt" />
<input type="submit" name="btn" value="submit">
</form>
<?php
session_start();
if ( isset($_POST['btn']) ) {
$_SESSION['counter'] += 1;
$_SESSION['val'][$_SESSION['counter']] = $_POST['txt'];
var_dump($_SESSION);
}
?>

Passing username to url in PHP MySQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am developing a site in PHP that allows users to sign up and enter in some information, and I would like to give each user a unique URL. When the user logs in to his profile, I want JUST the username to be passed to the URL (like www.mysite.com/profile.php?user=username) in order to rewrite it later. However, I'm using the $_POST method, and I'm concerned if I use $_GET while logging in the password will be passed to the URL as well. What should I do?
There shouldn't really be a problem doing this. You could simply use a POST method that points to a URL with a GET parameter.
So you make a POST request to:
www.mysite.com/profile.php?user={$username}
This way the user variable in the URL doesn't need to be used in the authentication.
Consider this for a simplistic example:
<form method="post" action="/profile.php?username=hasan">
<input type="text" name="username" value="hasan" />
<input type="text" name="password" value="********" />
</form>
The URL you are posting to doesn't have to be hard coded either - you could always dynamically add the user name before submitting the form.
On the link to or redirection you can add
Link to the profile
and after you read it (in php file) with $_GET['user']
Since the authentication presumably happens in a separate script, e.g. login.php, it's just a matter of appending the username to the profile URL when redirecting upon successful login.
header('Location: profile.php?username='.$username);
Lix's answer is best and is what you should be doing, but assuming you don't have a login.php and for some strange reason want to go straight to profile.php?user to login, you can use this javascript:
<script type="text/javascript">
$(document).ready(function() {
$("#theForm").submit(function() {
$(this).attr("action", $(this).attr("action") + $("#usernameInput").val());
return true;
});
});
</script>
And your form looks something like:
<form action="http://www.mysite.com/profile.php?user=" method="post" id="theForm">
<input type="text" name="usernameInput" id="usernameInput">
<input type="password" name="passwordInput" id="passwordInput">
<input type="submit" name="submit" value="Login">
</form>
And then your action will change to the inputted username upon submit. But still, you should have an intermediary login.php that redirects to profile.php?user.

Categories