I have my index.php page that has a form. After validation, the parameters from index.php are passed in the URL to another page called test1.php.
test1.php has pagination and because of that, the page keeps refreshing and my URL parameters vanish. I want my parameters to stay in test1.php while paginating because the parameters and the data from test1.php will be used in test2.php
index.php
<a href="test1.php?test=".<?php urlencode($var)?> > Go </a>
test1.php
$var1= $_REQUEST['test'];
<a href="test2.php?test=".<?php urlencode($var1)?> > Go </a>
test2.php
$param = $_REQUEST['test'];
It's probably because you are creating a variable named $param but using $params (with an "s") in your urlencode()
See $_SERVER['REQUEST_URI'] and concatenate your url with the already existing request variables.
Related
Im trying to send 2 arguments to my controller method from my view using GET.
I don't know exactly how to add my 2nd argument to the action URL.
Here I am sending only 1 argument.
action="/MVC/teacher/lookspecificMessage/<?= $details['person_receive_id']; ?>" method="GET">
However, I want to add this <?= $details['related_message']; ?>
I've tried using lookspecificMessage/<?= $details['person_receive_id']; ?>&<?= $details['related_message']; ?> but it dosen't work.
If URL rewriting is used, url should follow declared template.
In your case it can be
action="/MVC/teacher/lookspecificMessage/$person_receive_id/$related_message"
or
action="/MVC/teacher/lookspecificMessage/$person_receive_id/lookrelaredMessage/$related_message"
or any other form.
You should check rewriting rules to find correct template for url.
Using URL rewriting, you can have parameters in the main URL structure like that. Although, typically, GET parameters are passed at the end after a question mark like so:
example.com/path/to/page?param=1
If you want more than one parameter, you use the ampersand to separate them:
example.com/path/to/page?param=1&foo=bar
In your case, it looks like your .htaccess file is doing some URL rewriting or your framework is doing some magic, which is automatically extracting the parameter and setting it in the $_GET array.
And to be clear, here is how you could do yours:
<?php
// Get params
$receiveId = (int) $details['person_receive_id'];
$message = (string) $details['related_message'];
// Build URL
$url = "/MVC/teacher/lookspecificMessage/$receiveId?related_message=$message";
// Encode URL (in case message has weird values)
$url = urlencode($url);
?>
<form method="GET" action="<?php echo($url); ?>">
<!-- REST OF FORM HERE -->
</form>
Okay, so I have two pages, home.php and page.php. On home.php, I load page.php onto it using jquery. In the url of home.php there is a GET value, u. I want to access that GET value on page.php. You can see that I tried the regular $_GET method, but this does not work. If on page.php I can just get the url of home.php with the GET variables in the url, I can get the info from there. But right now I cannot get the url of home.php, it just gets page.php. I hope that makes sense and thanks for the help!
Home.php
<div id='holder'></div>
<script>
$('#holder').load('page.php');
</script>
Page.php
<?php
$u = $_GET['u'];
echo $_SERVER['PHP_SELF']; // echo's "page.php". I need it to echo "home.php?u=test"
//some php
?>
What you can do is pass the $_GET variable to the requested page.
Do it like this:
<div id='holder'></div>
<script>
$('#holder').load('page.php<?php echo "?u=" . $_GET[" u" ]; ?>');
</script>
Stackoverflow doesn't parse it the way I want but I'm sure it works.
I created a function that requires one parameter to be passed into it but I need that parameter to come from another script. How do I embed the variable into a link then put that variable into the function in another script? I know I need to utilize $_GET, isset($_GET['']) and a href but I just can't put it all together.
$_GET is collection of of query string parameters. If you had a url like: test.php?param1=foo¶m2=bar you can access foo by $_GET['param1'] etc..
Use $_REQUEST['something']
Your link must be:
Click Me
Inside test.php
if(#$_REQUEST['something']=="something"){
echo $_REQUEST['something1'];
}
When you click Click Me, test.php would echo "test".
I'm having some problems passing URL's as GET parameter. When I try to access:
http://www.linkebuy.com.br/linkebuy/parceiro?url=http%3A%2F%2Fwww.google.com
I get the following message:
However, if I go for:
http://www.linkebuy.com.br/linkebuy/parceiro?url=123
Everything works just fine (it redirects to an inexistent site - 123 -, of course, but it does the expected). By elimination I can say there's something wrong with the url parameter, but what is it?
OBS: I'm using rawurlencode() to encode the URL.
EDIT: Code you asked...
In the first view, where the link is (http://www.linkebuy.com.br/notebook/detalhe?id=5):
<!-- url() function just completes the right URL (production or development) -->
<a href="<?php echo url('linkebuy/parceiro/?url=' . rawurlencode($l->getUrl()), true) ?>" class="<?php echo $leadClass ?> oferta" target="_blank">
<?php echo $l->getNomeFantasia() ?>
</a>
When clicked the link redirects to an action (/linkebuy/parceiro), where happens the following (basicly nothing, just keeping in the framework):
public function execute($request, $response) {
$response->addParameter('url', rawurldecode($request->getParameter('url', ''))); //This creates $url in the view
$response->setTemplate('site/linkebuy/lead-parceiro.php'); //Forwards to the view
}
It includes the view, lead-parceiro.php (above on the question, I link to this page), where the head contains:
<script type="text/javascript">
setInterval(function(){ window.location = '<?php echo $url ?>'; },3000);
</script>
If you can't get rid of the restriction you can pass the url in 2 parts like this
http://www.linkebuy.com.br/linkebuy/parceiro?protocol=http&url=www.google.com
And then parse it on your code to make the full url for the redirect.
You should use urlencode when you pass anything as URL parameter
how do i set session variables on click of a link. I have many links on one page. based on the link clicked a session variable has to be set.
For instance:
i have 5 links
<a
href="page1.php">
page1
</a>
<a href="page2.php">
page2</a>
<a href="page3.php">
page3</a>
<a href="page4.php">
page4</a>
<a href="page5.php">
page5</a>
if the first link is clicked then $_SESSION['category']=page1 is to be set
if the second link is clicked then $_SESSION['category']=page2 is to be set and so on..
how do i get this?? any idea??
Your best bet is to set the $_SESSION['category'] at the beginning of each of those php files. If that is not an option, perhaps create a 'page.php' file that accepts a query string.
Something like this:
<?php //example: page.php?p=1
// don't forget to clean $_GET['p']
$p = $_GET['p'];
$_SESSION['category'] = $p;
include("page$p.php");
As gavinbear's suggestion for putting at the top of the page, you could use the following to get a match to your original naming convention:
$requested_uri = $_SERVER['REQUEST_URI']
$requested_path = parse_url($requested_uri)[path]
$_SESSION['category'] = basename($requested_path, ".php")
well you can always mix javascript with php.use the onclick event for the anchor tag. when the link is clicked just set your session in the javascript written for the onclick event.hope this make sense
On each page you will need to set the session.
For example on page1.php :
<?php
session_start();
$_SESSION['category']='page1';
?>
Any content on page1.php
and so on for each page.
If however you are wanting it to sit on the same page, but set the session and use that session to control something on the page (e.g. the category), then you could pass a parameter through the URL and set the session that way, e.g. an example would be page.php?category=page1
<?php
session_start();
if (isset($_GET['category'])) {
$_SESSION['category']=$_GET['category'];
}
?>
Any content on page.php
You don't really need sessions to detect the current page. Instead you can use this:
<?php
$pageName = basename($_SERVER[PHP_SELF]);
?>
I suppose you could then save that to a session variable, but it's going to be overwritten on every page.