I want to create a PHP file with $_GET[] function like this:
http://mywebsite.com/account.php?register -> Register page
http://mywebsite.com/account.php?login -> Login page
It's like a $_GET[] but without variable...
Someone can explain this to me?
<?php
if (isset($_GET['register']))
The variable will be set, but with no value
$_SERVER['QUERY_STRING'] contains the raw query string.
Related
I have this link:
www.something.com/index.php?page=teams
I then have this link:
Profile
I want to achieve is this link:
www.something.com/index.php?page=teams&profile=5
But I get this instead:
www.something.com?profile=5
The tricky part is that I can't just write the whole "path" like this:
Profile
Because it isn't always on the page 'teams'.
It might be a pretty stupid question, but i can't really figure it out.
You must include the page=teams parameter in the href.
Instead of
Profile
Something like
Profile
If that link is static you must need to update the html file.
But if page=anyvalue then you must generate the href link dynamically in your php code
for example:
Where $page is the current page, e.g $page="teams"
Well, you can just add it to the query string using http_build_query:
$newQueryString = http_build_query(['profile' => 5] + $_GET);
And then output it to your link:
Profile
Try something like this:
echo '<a href="'.{$_SERVER['SCRIPT_NAME']}.{$_SERVER['QUERY_STRING']}
.'&profile=5">Profile</a>
This makes use of $_SERVER to get the current page name (SCRIPT_NAME) and the existing query string (QUERY_STRING), and then appends "&profile=5" onto the end.
Well i have sort of fixed it.... i created a session called page, so i can access it everywhere. The thing is i can't get the variable $_GET['page'] because it's inside a included file called search.php, therefore i created the session.. But thanks for you suggestions guys!
I´ve got an url like this www.example.com/v=12345. This will go to my index.php site on my webserver and the variable 'v' is used to do some javascript stuff, which works fine.
Now i want to link to the document 'newsite.php" like this or similar: www.example.com/newsite.php/v=12345. This does not work since the css does not work anymore and i don't know why.. If i do it like www.example.com/newsite.phpv=12345 , the variable is read correctly but it opens the index.php again.. How can i do this correctly?
Thanks guys!
You should pass php variable in url as parameter like this:
www.example.com?v=12345
and in your php just get this value by:
$_GET['v']
It should solve your problems :)
Variables need the seperator ? between url and variable. And if you have more Variables, the variables are seperated with a &
Example:
www.domain.com/?v=123
www.domain.com/script.php?v=123
www.domain.com/?v=123&y=456
And every variable will be available via $_GET[]
$_GET['v']
$_GET['y']
I want to know how to pass a variable from one page to another in PHP without any form.
What I want to achieve is this:
The user clicks on a link
A variable is passed which contains a string.
The variable can be accessed on the other page so that I can run mysql queries using that variable.
use the get method in the url. If you want to pass over a variable called 'phone' as 0001112222:
<a href='whatever.php?phone=0001112222'>click</a>
then on the next page (whatever.php) you can access this var via:
$_GET['phone']
You want sessions if you have data you want to have the data held for longer than one page.
$_GET for just one page.
<a href='page.php?var=data'>Data link</a>
on page.php
<?php
echo $_GET['var'];
?>
will output: data
You can pass via GET. So if you want to pass the value foobar from PageA.php to PageB.php, call it as PageB.php?value=foobar.
In PageB.php, you can access it this way:
$value = $_GET['value'];
check to make sure the variable is set. Then clean it before using it:
isset($_GET['var'])?$var=mysql_escape_string($_GET['var']):$var='SomeDefaualtValue';
Otherwise, assign it a default value ($var='' is fine) to avoid the error you mentioned.
You can use Ajax calls or $_GET["String"]; Method
If you are trying to access the variable from another PHP file directly, you can include that file with include() or include_once(), giving you access to that variable. Note that this will include the entire first file in the second file.
i want to send a variable to xxx.php how i do it???
GET request would be
xxx.php?variable=something
and accessing $_GET['variable'] in php side would work.
Pass it as a command line argument
Set it in another PHP file and then include it
Put it in the query string then access it from $_GET or $_REQUEST
Put it in the POST data then access it from $_POST or $_REQUEST
Put it in a cookie then access it from $_COOKIES
Put it in a session variable then access it from $_SESSION
You can send the variable by using the GET method as:
http://www.example.com/welcome.php?fname=Peter
and access it from script as: $_GET["fname"]
Via the URL
for example
www.yoursite.com/xxx.php**?**myVar1=myValue1&myVar2=myValue2
seperate vars by &
or you can do it using a form , via Get
<form method='get'>
Step2:
in your PHP document
$_GET['myVar1']
$_GET['myVar2']
xxx.php?variablename=variablevalue
you can send the variable using $_POST or using $_SESSION to pass value of variable from one file to another
use query string in your code.
For example
$a = "myval" ;
< a href="xxx.php?var=$a" >
Get values by usnig $_GET['var'] , This would give you the query string value.
It's best you read up the basic about POST and GET first.
Here's a simple tutorial to get you started: http://www.tizag.com/phpT/postget.php
Via query string or in the header of the page
Pass it as query string:
xxx.php?your_var=var_value
I want to redirect my browser to a PHP page such that when the page loads, it will display to the user a substring of the current URL.
For example, let's say I have a page called substring.php.
My browser forwards me to:
http://www.example.com/substring.php?oauth_token=123456
Is it possible to write some PHP code that will then display to the user, "123456"?
If so, can anyone help me on how to do this?
Thanks!
All the query parameters in the URL will be inside the superglobal $_GET array, so you could simply do this:
echo $_GET['oauth_token'];
BE forewarned that if you're going to output anything that comes in from a URL (ie. user input), you should make sure to sanitize it properly for output. In this case, htmlspecialchars() would be prudent:
echo htmlspecialchars($_GET['oauth_token']);
<?php
echo $_GET['oauth_token'];
?>
Can't you just use the $_GET superglobal? It stores the contents of the query string part of the URI as an associative array:
echo $_GET['oauth_token'];
You can retrieve the value of oauth_token via the $_GET superglobal array:
echo $_GET['oauth_token'];
Of course you should use caution when outputting data you get as input from a user, but that's how it works in short.