Go to the menu - Go to the contents

[Site map] You are here --- > Newbies Paradise > Forums > Website > PHP > PHP problem > Read the topic

PHP problem

getting veriables from url...

You have to be registered to post messages

SolvedThis topic's problem has been solved

Page 1 
Author Message
1 visitor on this topic (1 anonymous user)
Page 1 
Offline yabberyabber # Posted on 02/03/2008 11:26:51 PM
i found pink mold in my trash
Avatar
Group : Members
i was doing a test to see if i could do some sort of login thing on my website, i cant get it to display my name variable...

here are my troubled scripts with url of moopher.php?name=yabberyabber
Code: PHP - Show / hide line numbering
  1. <?php
  2. if (isset($_Get['name'])){
  3.     echo $_GET['name'];
  4. }
  5. else
  6.     echo "account"
  7. ?>
  8. // and:
  9. <?php
  10. if (isset($_Get['name'])){
  11.     echo "<a href=\"logout.php\">logout</a>";
  12. }
  13. else
  14.    echo "<a href=\"welcom.php\">login</a>";
  15. ?>


my problem is that when i ttest it out (logging in from a separate page using PHP of course) instead if displaying yabberyabber, it displays account... and the link doesn't change to logout...
Edited on 02/04/2008 06:15:51 AM by yabberyabber

i need a french pen pal to show my fiend I'm cool
User image
 
Offline Lil'Gaß # Posted on 02/04/2008 05:27:28 AM
Avatar
Group : Read only
Hello, first in the page where you will get the veriables, use a ting like that for the links :

Code: PHP - Show / hide line numbering
  1. http://www.website.com/infos.php?day=27&amp;mount=07&amp;year=2003&amp;title=Informations


And for the page will receive te veriable, use a ting like that :

Code: PHP - Show / hide line numbering
  1. <p>Your fisrt name is <?php echo $_GET['name']; ?> , and your last name <?php echo $_GET['lastname']; ?>.</p>


Edit : I think you have miss to put the signe ; after your $_Get. Try this :

Code: PHP - Show / hide line numbering
  1. <?php
  2. if (isset($_Get['name'];)){
  3. echo $_GET['name'];
  4. }
  5. else
  6. echo "account"
  7. ?>
  8. // and:
  9. <?php
  10. if (isset($_Get['name'];)){
  11. echo "<a href=\"logout.php\">logout</a>";
  12. }
  13. else
  14. echo "<a href=\"welcom.php\">login</a>";
  15. ?>


I'm not sure about the last ting.

See you next time.
Edited on 02/04/2008 05:31:18 AM by Lil'Gaß

Act naturally - The Beatles

They're gonna put me in the movies
They're gonna make a big star out of me
We'll make a film about a man that's sad and lonely
And all I gotta do is act naturally :D
 
Offline yabberyabber # Posted on 02/04/2008 06:08:12 AM
i found pink mold in my trash
Avatar
Group : Members
no, it doesn't like that...

i need a french pen pal to show my fiend I'm cool
User image
 
Offline speedking # Posted on 02/05/2008 01:21:32 AM
I saw an Angel ...
Avatar
Moderators
$_GET must always be in upper case

User image
 
Offline yabberyabber # Posted on 02/05/2008 02:06:55 AM
i found pink mold in my trash
Avatar
Group : Members
thanks speedking, but i have a new problem now. i decided to use cookies (with the tizag tutoreal...) but the tutoreal didn't explain very well... and i cant get my script to pick up the cookie (web developer tool bar doesn't say it was even made...) so here is my new troubled code:(using the basic code from the protecting website from intruders tutoreal...)
Code: PHP - Show / hide line numbering
  1. $user_name = $_POST['user_name']; //i know theres no problem with this line because
  2. setcookie('name', $user_name);  //the tutoreal i used said if you don't set expiration, it will die when you close browser window...
but heres also the code for picking up the variable:
Code: PHP - Show / hide line numbering
  1. if(isset($_COOKIE['user_name'])){
  2.     echo $_COOKIE['user_name'];
  3. }

srry if i missed something redundant and/or obvious... ohh yea, and the example on Tizag doesn't work...
thanks in advance :)
ok so i just figured out that it is creating cookies, but they are only working for the file that created it... and the cookie wont stay for my 'home page'
fixed it! i just had to have them in the same folder... (i wish Tizag would have told me that in their tutoreal...)
Edited on 02/16/2008 08:31:57 PM by yabberyabber
Offline yabberyabber # Posted on 03/13/2008 04:39:29 AM
i found pink mold in my trash
Avatar
Group : Members
sorry for unearthing and adding yet another question to this topic but...

is there a way to made cookies last forever? i finally got the hang of them and i was trying to make the member zone (from the php tutoreal example) so that it would automatically log in when i went there (and no its still on my hard drive...)

i need a french pen pal to show my fiend I'm cool
User image
 
Offline mwsaz # Posted on 03/13/2008 07:10:27 AM
Tremulous : open source FPS
Avatar
Validators
You cannot set a cookie forever, but you can make it last, hum, let's say 50 years :D
Code: PHP - Show / hide line numbering
  1. <?php
  2. setcookie('my cookie', 'its value', time() + 3600*24*365.25*50);

Or 10 years
Code: PHP - Show / hide line numbering
  1. <?php
  2. setcookie('my cookie', 'its value', time() + 3600*24*365.25*10);

or 100
Code: PHP - Show / hide line numbering
  1. <?php
  2. setcookie('my cookie', 'its value', time() + 3600*24*365.25*100);

etc...

Computers are like air conditioned : they stop working when you open windows.
About tutorial validation: I deal with newly submitted tutos every Monday, Wednesday and Thursday.
 
Offline speedking # Posted on 03/15/2008 12:22:51 AM
I saw an Angel ...
Avatar
Moderators
Won't go further than 2036 though (that's the maximum the 32-bits unix counter can handle).

User image
 
Offline mwsaz # Posted on 03/15/2008 08:38:46 AM
Tremulous : open source FPS
Avatar
Validators
...unless your server has a 64x processor and that your version of php handles it (php6?) :)
Edited on 03/15/2008 08:39:47 AM by mwsaz

Computers are like air conditioned : they stop working when you open windows.
About tutorial validation: I deal with newly submitted tutos every Monday, Wednesday and Thursday.
 
Offline yabberyabber # Posted on 05/07/2008 07:29:03 AM
i found pink mold in my trash
Avatar
Group : Members
sorry for again unearthing and adding yet another question to this topic but...

does NP use sessions or cookies for account login stuff? i have a good source and understand both of them, but which one is most standard (i hate being off standard). and how does NP keep account info secure so you cannot hack into others accounts? is it simply hashing (md5();) user name and password then checking with the database on each page load? or is it something more. is that kind of info even safe to share with people (is security of accounts that important if its not really anything dealing with money?).

next time i have a question on php should i start a new topic or just keep adding on this for a while?
Edited on 05/07/2008 07:31:38 AM by yabberyabber

i need a french pen pal to show my fiend I'm cool
User image
 
Offline Delroth # Posted on 05/07/2008 11:12:15 PM
Group : Members
yabberyabber: when you log in on NP, it compares your password's sha1 hash with the one stocked in the database. If you can log in, it will place a variable in the session data (like for example $_SESSION['logged_in']), which will be used to make the website remember you are logged in.
Offline yabberyabber # Posted on 05/09/2008 01:36:23 AM
i found pink mold in my trash
Avatar
Group : Members
so $_SESSION['logged_in'] is just a bool value? and then when they leave it just says "session destroy"

i need a french pen pal to show my fiend I'm cool
User image
 
Offline alex.css # Posted on 05/16/2008 09:22:52 PM
Trust nobody, do it yourself !
Avatar
Group : Members
$_SESSION may contain chars like : "A b c d, 0 1 2 3 4 ... , TRUE / FALSE". (If not, It works for me xD)

I don't know if it's solved but $_SESSION is a way easier than $_COOKIE (for me) .
Code: PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
if(isset($_SESSION['Member']))
{
 echo("You are logged");
}
else
{
 echo("You are not logged");
}
?>


Create a form which will create a member access (just a simple):
Code: PHP
1
2
3
4
5
6
<?php
if(isset($_POST['member_name']))
{
 $_SESSION['Member'] = $_POST['member_name'];
}
?>

After, go to the page where the first code was placed. If the sessions work correctly, you should see : You are logged.
However, if the session doesn't work, it should return you : You are not logged

After, you can create a page which will destroy all session vars :
Code: PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
if(isset($_SESSION))
{
 // erase all sessions. I think you may specify which one you want to destroy. Refer to the manual
 session_destroy();
 header("Location: index.php");
}
else
{
 header("Location: index.php");
}
?>

If you still get the "You are logged" message, it means that the session_destroy() doesn't work (for any reason).

Alex.css
Edited on 05/16/2008 09:24:45 PM by alex.css
 

Back to "PHP" or to the boards list

You have to be registered to post messages

Change your template | Learn more about NP | Site map | Terms of use | Rules | RSS feed | XHTML 1.0 | CSS 2.0
Powered by Simple IT SARL: Contact us

There is nothing else to read, you have to go up now !

Do you want to be published here? Contact us.

Number of Newbies connected 3 Newbies Connected | SQL requests 8 Requests | Page loading delay 0.0605s (0.0503s)