PHP Variables from URL
Are you facing problem passing PHP variable from URL? Don't worry, it is quite easy to learn and implement into your project. Remember one thing if you are passing unnecessary information in the URL is fine but if you are passing confidential information like password or username in the URL, It would be dangerous for you. Let see both the example :
Example 1 : (page1.php)
<title>Sending Variable from URL</title>
a href="page2.php?myname=Suraj Mittal&mycompany=roseindia">Send variables from URL</a>
$uname = $_GET['myname']; $cname = $_GET['mycompany'];
echo "My Name is : ".$uname."<br/>"; echo "My Company name is : ".$cname;
The output of the above example is : My
Name is : Suraj Mittal
My Company name is : roseindia.
In the above example you can see that in the first page we made a link and passed the variables in the URL. It means if you click the link you will go to the next page and your whole information will appear in the url. But sometime it will create problem for you to show your information in the URL. How see the example below :
Example 2 : Page1(login.php)
<form action="welcome.php" method="get">
<table width="300" align="center" cellpadding="2" cellspacing="2" border=""1>
<tr> <td>Username :</td> <td><input type="text" name="userid" /></td> </tr> <tr> <td>Password :</td> <td><input type="password" name="passid" /></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" name="submit" value="Submit" /></td> </tr>
$username = $_GET['userid']; $password = $_GET['passid']; echo "Welcome ".$username."!"."<br/>"; echo "Your Password is ".$password.".";
The output of the above example is :
Your Password is srmt123.
In this example, we used two files first one is your basic html code file and the second one where we send the information through $_GET method. By mentioning method in the form we can transfers the information from one page to another. Here, we use $_GET method to send information to the other page. Note that $_GET method send the whole information in the above URL and it is not advisable to use this method because anyone get your information through URL. For example: If you are signing up for any side and you fill your username and password and submit the form. At that moment your personal information shown in the URL and anybody can take it from there. It might be shown like that :
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.