I have written one script in php called login.php using POST method to get username and parameter field and this will be redirecting to other script
header("Location: host_ack_api.php?username=$Userlogin&password=$Userpassword&host_name=$server&comment=$Comments");.
I want to hide these parameters in address bar while redirecting.
While the second script host_ack_api.php are written using GET
Option is make it by $_POST to another file or same
Option you can creat $_SESSION when you use your GET like you have username=$Userlogin and when you get that username make some $_SESSION variable and put data intro session and after that you can make page refresh to remove your get parameters from URL and use it from session.
PS - your method was GET not POST
Related
For example, I have a page called profile_page.php. This page is only functional if data is written after the ?u= in the URL, for example, data for Alice's profile page can only be seen when the URL reads http://localhost/profile_page/alice.
Loading http://localhost/profile_page will give me undefined variable errors as most of my variable's are depending on the URL to have a value after the ?u=. For example, the variable $firstname can only be gathered when I get her username in the URL.
In such a case, when http://localhost/profile_page, I would rather have it redirect the user to their own profile_page, but I don't know how I can test the URL and parse it through an if statement.
I understand you can use $u=$_GET['u']; to obtain the current page URL? but I don't think doing this, is the best way to go about it:
$u=$_GET['u'];
if ($u == "http://localhost/profile_page/"){
// redirect to logged in users page code here
}
First, if you are using some parameter for your page to build, the url would looks like httlp://localhost/profile_page.php?firstname=alice&lastname=brown, with $_GET['firstname'] you will get alice in this case. If you want to test if the parameter is set first and redirect to another page if it is not set, you could use
if(!isset($_GET['firstname'])
{
header('Location:redirected_page.php');
}
I have a php code sending data to django.
I want django to redirect response to another php page instead of the previous one.
Here is my view which is called from PHP :
def search(request):
arg = { 'Score':clf.predict_proba(my_sample)}
response=redirect('redirected_url.php',arg)
return (HttpResponse(response)
query_arg is a value I want to pass to another php page and show it.
I have tried
return HttpResponseRedirect('redirected_url.php'.arg)
and it did not work either!
How should I proceed?
Best
You can't use redirect with arg as a second parameter in Django. That parameter determines whether it's a permanent redirect or not. Regardless, the *args option there is for extra data to pass to redirect, not for your variables.
If you're redirecting to another page, you need to pass your variables as a query string. For instance, you could pass a variable name when redirecting in Django this way:
return HttpResponseRedirect('redirected_url.php?name=alex')
And then access it from your PHP script via the superglobal $_GET['name'].
I'm trying to carry a file that is uploaded through to a second script. I'm using an HTML form for the file upload and php to save the file. The PHP variable is:
$_FILES["Picture"]["name"]
I know when you create a POST html form and hit submit, then the following page has access to: $_FILES["Picture"]["name"].
But now I want to redirect using header to another page and have access to $_FILES["Picture"]["name"].
Is there a way to do that.?
Store $_FILES array in $_SESSION like $_SESSION['file'] = $_FILE["Picture"]["name"] and access session $_SESSION on another page/script
Try saving the data you want into the session, then it's accessible in subsequent calls. $_SESSION is what's known as a superglobal. You can also use $_COOKIE to save it to the user's cookies instead of the server session.
Something like this:
$_SESSION['picture'] = $_FILES['Picture'];
Then to print it later all you have to do is the following, like any other array:
echo $_SESSION['picture']['name'];
use cURL to request the second page with the exact same headers from the first request
I have a php script that checks if the user typed the right password for the right username.
If its right I want to open another php page and pass some values with the get method. How do I do this? Im pretty new to php.
You can redirect to that page if this is your case:
if(condition){
header("Location: yourfile.php?parameter1=value1¶meter2=value2");
exit();
}
Note: header should be called before any output, its recommended to call it at top of the page before printing anything.
Or use cURL to send the GET request.
Don't use GET to send password!
Instead try to use cURL lib and send it via POST.
i am trying to send header from a php file that is called with ajax. problem is, when i validate all information with php, i want to redirect to another page but headers dont work! any ideas?
what the code does:
//------------- index.php
on click of input, function passes <input> values through $_POST to login.php
if($_SESSION[superman]==true){redirects to index_main.php}
//------------- login.php
all it does is validate forms and if login and password are correct, it sets $_SESSION [superman]=true
The redirect will only redirect the Ajax call! If you want to change the displayed page in the browser, you'll need to redirect using Javascript once the Ajax call completes.
Make your Ajax call return a value indicating successful login (for example the string true or maybe the URL to the page you want to load)
Check the return value of the Ajax call. If success, change location.href using Javascript.