This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-17 11:27:40

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

PHP: Read URL in Broswer?

How do I make it read part of the current url in the browser, for example:
Read the "something=something" part of "http:/something.eg/something?something=something"

I searched in Google, but didn't get the right answer.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#2 2011-09-17 11:52:21

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

Anyone?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#3 2011-09-17 11:55:37

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: PHP: Read URL in Broswer?

Well, you could do something like this:

Code:

$something = $_GET['something']

To read the value of "something=something" but other than that i don't know!


Fork Clamor on GitHub!

Offline

 

#4 2011-09-17 11:58:18

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

That doesn't read teh current url from the browser


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#5 2011-09-17 12:00:29

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: PHP: Read URL in Broswer?

Well, it can be done with JS

Code:

location.search

if I remember correctly.

Or if you _NEED_ it to be in PHP, just parse the string with a regex.


http://www.danasoft.com/citysign.jpg

Offline

 

#6 2011-09-17 12:08:07

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: PHP: Read URL in Broswer?

WindowsExplorer wrote:

That doesn't read teh current url from the browser

sorry, misunderstood  tongue


Fork Clamor on GitHub!

Offline

 

#7 2011-09-17 13:22:10

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

Well, I need it to be in php.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#8 2011-09-17 13:51:34

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

it doesn't have to be in php, just i want a thing so if the url is http://example.com/image?type=example1

It will show a certain image, and if teh url is http://example.com/image?type=2 it shows another image.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#9 2011-09-17 14:22:21

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: PHP: Read URL in Broswer?

so you COULD use my method to find out which image to display!


Fork Clamor on GitHub!

Offline

 

#10 2011-09-17 14:29:26

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

Yes, but ur method doesn't read anything from the address bar.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#11 2011-09-17 15:47:28

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP: Read URL in Broswer?

Look, WindowsExplorer:

the "variable=value" bit of the URL
http://domain.com/page?variable=value
is called a GET variable.

So, in this specific context, you can read a value using ohaiderstudios's method:
$_GET['variable']

However, it's true that sometimes you might want to find the full URL of the request. Then you need
$_SERVER['REQUEST_URI']
but not in this case!

Offline

 

#12 2011-09-17 15:51:39

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

ohaiderstudios wrote:

Well, you could do something like this:

Code:

$something = $_GET['something']

To read the value of "something=something" but other than that i don't know!

Oh, sorry ohaiderstudios! I didn't realize. I thought that was to set a global var or something!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#13 2011-09-17 18:28:32

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: PHP: Read URL in Broswer?

WindowsExplorer wrote:

ohaiderstudios wrote:

Well, you could do something like this:

Code:

$something = $_GET['something']

To read the value of "something=something" but other than that i don't know!

Oh, sorry ohaiderstudios! I didn't realize. I thought that was to set a global var or something!

yeah, it's just reading the value of "something=something" and setting it to variable


Fork Clamor on GitHub!

Offline

 

#14 2011-09-17 18:32:48

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

Great! I'm making a CUSTOM UPDATING IMAGE CREATOR!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#15 2011-09-17 18:46:12

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: PHP: Read URL in Broswer?

WindowsExplorer wrote:

Great! I'm making a CUSTOM UPDATING IMAGE CREATOR!

I figured that's what you were going to do with it  wink


Fork Clamor on GitHub!

Offline

 

#16 2011-09-17 18:47:14

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

Also, I don't fully get string replacement. Could someone give me the code, and explain the parts of it?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#17 2011-09-17 19:14:48

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: PHP: Read URL in Broswer?

Code:

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

echo curPageURL();

Put the fumction at the top of the page in php tags. I use this one all the time.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#18 2011-09-18 02:45:32

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: PHP: Read URL in Broswer?

WindowsExplorer wrote:

Also, I don't fully get string replacement. Could someone give me the code, and explain the parts of it?

Heres some example code:

Code:

$helloworld = "hello world!"; //sets the variable
//lets replace all "o"s and change it to "v"
$helloworld = replace("o","v",$helloworld);
echo $helloworld;

That will show: hellv wvrld!

Basically: replace(replace this, with this, from this);
You can also do blank for the 2nd field, which would remove all of the 1st field from the 3rd field.

Get it?


Hai.

Offline

 

#19 2011-09-18 03:07:10

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP: Read URL in Broswer?

Thanks sparks, fg123, LS97 and orchardstudios!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#20 2011-09-18 11:40:20

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: PHP: Read URL in Broswer?

WindowsExplorer wrote:

Thanks sparks, fg123, LS97 and orchardstudios!

OHAIDER studios


Fork Clamor on GitHub!

Offline

 

#21 2011-09-18 11:51:32

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP: Read URL in Broswer?

ohaiderstudios wrote:

WindowsExplorer wrote:

Thanks sparks, fg123, LS97 and orchardstudios!

OHAIDER studios

LOL, orchard  lol   lol

Offline

 

#22 2011-09-18 14:14:27

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: PHP: Read URL in Broswer?

lol

No problem!  smile


Hai.

Offline

 

Board footer