what kind of php is there?

hey guys

i just wondering what type of php coding is there? i notice there is 2 types of php coding , one of them is like “site.com/profile.php” and the other is like “site.com/index.php?name=profile”… what is the difference between them and what are they called?

That’s exactly the same, only the second example is passing data to index.php via a “GET” request. In index.php you could do:

[php]echo $_GET[‘name’]; //this would output (in your example):profile[/php]

ohh nice very fast answer :smiley: … ohh now i understand , i heard there are more security risks using $_GET method ? and i also wondering if its hard to convert the script so it use the files instead like “profile.php”. ( you might be wondering what i am doing ? the thing is that i found a script that i will be modifying simple stuff to learn instead just watching videos) … i dont know much about php so please excuse me :’(

Yes most people when submitting forms or any other method of transmitting data will tend to use the POST method as it is sent through the page request with no traces (to the average user). You could send the same data to a file, but using GET your URL would be:

(not so secret)
[php]//URL = index.php?mysecretcode=abc123
$mycode = $_GET[‘mysecretcode’];[/php]

(much more secret)
[php]//URL = index.php
$mycode = $_POST[‘mysecretcode’];[/php]

Of course, always clean any data from $_POST or $_GET as either set of data can be tampered with. List of useful functions for this below:

[ul][li]trim() - http://uk.php.net/trim[/li]
[li]strip_tags() - http://uk.php.net/strip_tags[/li]
[li]addslashes() - http://uk.php.net/addslashes[/li][/ul]

the script only use $_get for public stuff like “site.com/page.php?name=picture&id=1” but while loging in it use the $_post method , so there no risks right ? and also is it hard to convert php coding type from “page.php?name=picture&id=1” to “site.com/picture.php” ?

Hard to say, but for changing it, if ?name=picture&id=1 appears from a element with an action of “GET”, then you can just change the HTML of the form to say action=“POST” and the PHP to use $_POST instead of $_GET.

However, those URLs may be created by an anchor tag () for which there is not a POST alternative (typically anyway - there kind of is, but not in standard HTML).

ohh i am going to try do that and as exmple , what about this line , how do u do here ?
[php]

if (!isset($_GET[‘name’]) or trim(empty($_GET[‘name’])))
{ $name = ‘welcome’; }

else
{ $name = mysql_real_escape_string($_GET[‘name’]); }

[/php]

Providing the HTML has been changed accordingly, just replace all $_GET with $_POST

so did it like this [php]if (!isset($_POST[‘name’]) or trim(empty($_POST[‘name’])))
{ $name = ‘welcome’; }

else
{ $name = mysql_real_escape_string($_POST[‘name’]); }[/php] and got following error

[code]Warning: mysql_query() [function.mysql-query]: Access denied for user ‘a9205753’@‘localhost’ (using password: NO) in /home/a9205753/public_html/pages/welcome.php on line 8

Free Web Hosting

PHP Error Message

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a9205753/public_html/pages/welcome.php on line 8

Free Web Hosting
Access denied for user ‘a9205753’@‘localhost’ (using password: NO)[/code]

The change regarding $_POST should have had no part in causing the error you posted. The errors say you’re using the wrong credentials for your database.

yh , it was because i had not included the con.php(database information) in the welcome.php

while using the $_get method , how do i add new page to the other like “site.com/page.php?name=fun” , everytime i write that in the url i get a message “the page your seeking is does not exists”… i notice that there is following code in the page.php [php]if (mysql_num_rows($page_sql) == 0)
{ echo ""; exit; }
[/php]
its seem like the new page is not registered

so would be thankful if you could tell how to add a new page?

Add a new page in what? I don’t know what you’re using (I’m assuming you haven’t written this yourself). You say that there is already a page.php with code in it - if you cannot access it you’ll need to check the documentation for the framework/software you’re using.

i notice that all pages are registered in the database with the url to access , i will check it out and get back to u

in the database tabel it shows like :

Rows URL
1 | pages/userlist.php
1 | pages/profile.php

how do i edit these rows ?

How are you viewing them? If you’re using commandline you can use that, or phpmyadmin is easier, because when you’re viewing the list of values you can just click the edit button. Again, I can’t tell you how to edit them unless I know what you’re using, or what you have available.

ohh now i got it thanks :slight_smile:

and on thing more :slight_smile: ! how do i change the word name in the url, /page.php?name=welcome , i wanna have “action” intead of “name” kinda like smf ?

Just change any href attributes on your links to say ?action= instead of ?name= and then look through the code for $_GET[‘name’] - change all occurrences of this to $_GET[‘action’]. That should be it sorted.

these are the all $_GET using name
[php]if (!isset($_GET[‘name’]) or trim(empty($_GET[‘name’])))
{ $name = ‘welcome’; }

else
{ $name = mysql_real_escape_string($_GET[‘name’]); }
[/php]

changed them but still url not changed ?

Sponsor our Newsletter | Privacy Policy | Terms of Service